Describe the differences in space requirements for array-based binary trees and complete binary trees.
Binary tree:
O(2^n)
Complete binary tree:
O(n)
Complete binary tree: All layers (except possibly the last) are full, and all leaves are either: (1) at the maximum depth, d, and as far left as possible OR (2) to the right of all internal nodes at depth d-1.
Sparse: |E|<<|V|^2
Dense: |E| ~~ |V|^2
Branch and bound: optimization; estimate partial solutions; run until everything is tested and return the best
DFS: stack
Provide the order of edges being added to the MST (starting at A) using Prim's on the following graph.
OR
(a, b), (b, d), (d, c), (c, f), (f, g), (f, e)
At function exit (return), store the input, output pair*
* this may not be an actual pair: use an appropriate data structure
Provide the order of edges being added to the MST (starting at A) using Kruskel's on the following graph.
* most of the time
The complexity of inserting into a hash table with m slots that stores n unique keys.
BST: n
This algorithmic technique BEST describes the following code.
Compute the maximum value for backpacks of size k as follows:
For each item with (size, value), compute "max value for backpack k - size" + value; take the largest of these.
Assume the hashing function is just "mod 8". Where will 14 be inserted with linear probing and quadratic probing? Which is better?
Quadratic: 2
Quadratic requires fewer probes
The AVL tree after inserting
4, 2, -1, 5, 7, 8, 9, 13, 12, 10
Give the shortest path from "a" to all other vertices in the following graph.
There are many examples. One is:
12 cents: 1 cent, 6 cent, 10 centGiven two strings str1 and str2 and below operations that can performed on str1. Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.
Operations: Insert, Remove, Replace
All of the above operations are of equal cost.