CS | Priority Flashcards
What is the relationship between best/worst/expected case and big O/theta/omega?
algorithms big-O
Best/worst/expected case describe big O for particular inputs or scenarios. Big O/theta/omega describe the upper/lower/tight bounds for the runtime.
Cracking the Coding Interview 6E p.40
When the number of elements gets halved each time, this indicates big O of what?
algorithms big-O
O(log N)
Cracking the Coding Interview 6E p.44
When you have a recursive algorithm with multiple calls, what is the big O likely to be?
algorithms big-O
O(branches^depth). E.g. O(2^N).
Cracking the Coding Interview 6E p.45
Big O describes the __ __ . Draw a graph to depict this for some of the common big O times.
algorithms big-O
Rate of increase. (See source material.)
Cracking the Coding Interview 6E p.41-42
When do you add runtimes (simple phrase)? When do you multiply runtimes (simple phrase)?
algorithms big-O
Add: If your algorithm is in the form, “do this, then, when you’re all done, do that”. Multiply: If your algorithm is in the form, “do this for each time you do that”.
Cracking the Coding Interview 6E p.43
Steps of the problem-solving flowchart.
(See source material.) Listen: write the unique information down. Example: Draw a specific, large enough, not special case example. Brute force. Optimize with BUD; unused info, manually on an example, solve it incorrectly, make time vs space tradeoff, precompute. Walk-through. Implement: modularized, error checks, classes, var names. Test: conceptual, weird code, hot spots, small test cases, special cases.
Cracking the Coding Interview 6E p.62
What are 5 optimize and solve techniques?
BUD; DIY; simplify and generalize; base case and build; data structure brainstorm.
Cracking the Coding Interview 6E p. 67-72
What is great way to figure out the runtime of a recursive algorithm?
Draw the recursive calls as a tree.
Cracking the Coding Interview 6E p. 132
When you see an algorithm with multiple recursive calls, what is the likely runtime?
Cracking the Coding Interview 6E p. 53
exponential
Cracking the Coding Interview 6E p. 53
What is the ordering property of a binary search tree?
Cracking the Coding Interview 6E p. 101
all left descendants <= n < all right descendants
Cracking the Coding Interview 6E p. 101
Can a binary search tree have duplicates?
Cracking the Coding Interview 6E p. 101
Clarify with the interviewer.
Cracking the Coding Interview 6E p. 101
Does balancing a tree mean that the left and right subtrees are the same size?
Cracking the Coding Interview 6E p. 101
No.
Cracking the Coding Interview 6E p. 101
What is a complete binary tree?
Cracking the Coding Interview 6E p. 102
Every level of the tree is fully filled except perhaps the last one, which is filled left to right.
Cracking the Coding Interview 6E p. 102
What is a full binary tree?
Cracking the Coding Interview 6E p. 102
Every node has either 0 or 2 children.
Cracking the Coding Interview 6E p. 102
What is a perfect binary tree? Should you assume a binary tree is perfect?
Cracking the Coding Interview 6E p. 102
Both full and complete. No.
Cracking the Coding Interview 6E p. 102
What is a min-heap?
Cracking the Coding Interview 6E p. 103
Complete binary tree where each node is smaller than its children.
Cracking the Coding Interview 6E p. 103
Basic idea of insertion into a min heap. Time complexity?
Cracking the Coding Interview 6E p. 104
Bottom, rightmost; bubble up. O(log n).
Cracking the Coding Interview 6E p. 104
Basic idea of extracting min element from a min-heap?
Cracking the Coding Interview 6E p. 104
Remove root; swap root with last element; bubble down.
Cracking the Coding Interview 6E p. 104
Runtime of a prefix check in a trie?
Cracking the Coding Interview 6E p. 105
O(K) where K is the length of the string
Cracking the Coding Interview 6E p. 105
If a problem involves a list of valid words, or searching on related prefixes repeatedly, use a ?
Cracking the Coding Interview 6E p. 105
Trie.
Cracking the Coding Interview 6E p. 105