Search Results


7 matches found for 'heap'

Stack Memory vs. Heap Memory

... = faster lookup Can result in the dreaded stack overflow Heap Memory The heap memory is used within the context of an application, which may use one or more threads.


Merge k sorted linked lists

... keep track of the smallest values. Since there are \(k\) linked lists, we can use a binary heap to keep track of \(k\) nodes, since we only need to keep track of at most \(k\) nodes with distinct indices.


Algorithm Handbook

... find min/max k problems by recording the row and column of the 2D matrix value as an entry in the heap, allowing you to effectively find sorted values in less than \(O(n^2)\) time. For rotating a 2d array, there is a 2-step program Transpose the matrix (Turn Columns to Rows): [[1, 2],[3, 4]] => [[1, 3],[2, 4]] Invert the rows (mirror): [1, 2, 3] => [3, 2, 1] # Transpose a 2d matrix for j in range(0, n): for i in range(j, n): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] Linked Lists Use a slow and a fast pointer for linked list nodes To get to the half-way point of a linked list efficiently, simply increment the fast pointer by 2 and the slow pointer by 1.


Java Essentials

... will excel for cross-platform support due to the JVM. Heap vs. Stack The heap is a part of memory that is reserved for allocation of reference types (i.e. Objects).


Javascript Essentials

... Empty set let s = new Set(); Set with values let s = new Set([1, 2, 3]); Min heap goog.require('goog.structs.Heap'); let h = new goog.structs.


Python Essentials

... = {'a': 'b'} Empty set s = set() Set with values s = set([1, 2, 3]) Min heap import heapq q = [] heapq.heappush(q, 1) heapq.


Algorithm Interview Problems

Welcome This page contains solutions to common interview problems that may be encountered. Arrays Longest Substring Without Repeating Characters Rotate a 2D Matrix Buy/Sell Two Stocks Merge Intervals Next Permutation Random Permutation Replace all occurrences of a space with a string Linked Lists Reversing sublists of singly linked lists Cycles in singly linked lists Overlapping singly linked lists Merging two sorted singly linked lists Merge k sorted lists Recursion Counting the path of sums Money Denominations Phone Number Mnemonics Unique Permutation Dynamic Programming Perfect Squares Find the Maximum Min Path Binary Trees Tree Symmetry Iterative In-Order Traversal of a Binary Tree Construct a Binary Tree from Pre-Order Traversal and In-Order Traversal BST Validate a BST Binary Heaps Merge k sorted lists Graphs Find a path in a maze from start to finish Flip colors in a matrix Search Search in a rotated sorted array Find the Duplicate Number Greedy Algorithms Queue Reconstruction By Height Trie Build a Trie in Python Invariant Compute the max.