REIR
True or False. Bottom-up mergesort does not require the use of extra space.
False
True or False? DFS is not an appropriate strategy for determining whether a graph contains a cycle
False
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. Any MST of G must exclude the edge of maximum weight.
False
True or False. Mergesort can be improved by using a different method for small subarrays
True
True or False. Mergesort is stable.
True
True or False. To sort an array of N elements, standard mergesort implementations need extra space proportional to N
True
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. Any MST of G must include the edge of minimum weight.
True
Describe the number of times that MergeSort assigns a value to an array entry, for randomly ordered array of distinct values
linearithmic
Describe the number of times that QuickSort assigns a value to an array entry, for randomly ordered array of distinct values
linearithmic
Give the order of growth of the running times of the Heapsort sorting algorithm for arrays that are already in order
linearithmic
Give the order of growth of the running times of the Heapsort sorting algorithm for arrays that are in reverse order.
linearithmic
Give the order of growth of the running times of the Quicksort sorting algorithm for arrays that are already in order
linearithmic
Give the order of growth of the running times of the Quicksort sorting algorithm for arrays that are in reverse order.
linearithmic
Give the order of growth of the running times of the Shellsort (with increments 1, 4, 13, 40, ...) sorting algorithm for arrays that are already in order
linearithmic
quick-union with path compression. describe the order of growth of the height of an N-node tree in the best case
1
weighted quick-union. describe the order of growth of the height of an N-node tree in the best case
1
Give the order of growth of the running times of the Shellsort (with increments 1, 4, 13, 40, ...) sorting algorithm for arrays that are in reverse order.
?
What is a collision in a hash table implementation of a symbol table?
A collision occurs when two key-value pairs have different keys but hash to the same index.
What is the primary reason to use double probing instead of linear probing?
Achieve same search times with less memory
why you'd use one instead of the other?Breadth-first search vs Depth-first search
BFS: shortest path DFS: topological sort, strongly connected components
Maintain a symbol table that supports insert, search, sort and select operations with comparable keys
BST
assume P != NP. Determine whether a digraph is a DAG.
Can be solved in exponential time in the worst case.
assume P != NP. Enumerate all subsets of a set of size N such that every pair of adjacent subsets differs in exactly one item.
Can be solved in linear time in the worst case.
assume P != NP. Find a longest path from s to t in an edge-weighted DAG.
Can be solved in linear time in the worst case.
Find a shortest path in an edge-weighted digraph with no negative edge weights.
Dijkstra
unweighted graph : BFS :: weighted graph :______
Dijkstra's algorithm
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. Any shortest path from s to t in G must exclude the edge of maximum weight.
False
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. Any shortest path from s to t in G must include the edge of minimum weight.
False
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. If the weights of all edges in G are increased by 17, then any shortest path from s to t in G is a shortest path in the modified edge-weighted digraph.
False
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. If the weights of all edges incident to any vertex v are increased by 17, then any MST in G is an MST in the modified edge-weighted graph.
False
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. The shortest path from s to t in G is unique.
False
True or False? Search time in a TST built from randomly ordered keys is logarithmic in the number of keys on the average.
False
True or False? The shape of a TST depends only on the set of keys that were used to build it, not the order in which they were inserted.
False
true or false. It is possible to insert any batch of N keys into an initially empty binary search tree using at most 2N compares.
False. If you could insert any N comparable keys into a BST using 2N compares, then you could sort those N keys using 2N compares by performing an inorder traversal of the BST. This would violate the sorting lower bound.
true or false. Let a[] be a max-oriented binary heap that contains the N distinct integers 1, 2, . . . , N in a[1] through a[N]. Then, key N must be in a[1]; key N − 1 must be in either a[2] or a[3]; and key N − 2 must be in either a[2] or a[3].
False. Key N − 2 can be also be a grandchild of the root node: a[4], a[5], a[6], or a[7].
What is the primary reason to use the Boyer-Moore right-to-left scan algorithm instead of the Knuth-Morris-Pratt algorithm?
Faster average-case search
What is the primary reason to use a binomial queue instead of a binary heap?
Faster join
What is the primary reason to use a randomized BST instead of a binary heap?
Faster search
Maintain a symbol table that supports insert and search operations with primitive-type keys.
Hashing
Given an array of N 64-bit long integers, find two integers x and y such that x + y = 0. Describe a efficient algorithm for TwoSum in the box below. Your algorithm should run in linear time on average (for full credit) or linearithmic time (for partial credit).
Hashing. Insert each integer x into a hash table (linear probing or separate chaining). When inserting x, check if −x is already in the hash table. If so, you've found two integers that sum to 0. The running time is O(N) on average, under the assumption that the hash function maps the keys uniformly. The running time is quadratic in the worst case, if all the keys hash to the same bin.
Modern computers have memory caches, which speed up reads and writes if they are to locations near recently-accessed memory. This makes sequential access to memory faster, in general, than random access. Which sorting algorithm you would expect to benefit least from caching?
Heapsort
possible , impossible, or an open research problem? Design a priority queue implementation that performs insert, max, and delete-max in ∼ 1/3 lg N compares per operation, where N is the number of comparable keys in the data structure.
Impossible
assume P != NP. Compress the strict majority of 10MB files by more than 3 bits.
Impossible.
assume P != NP. Find a longest path from s to t in an edge-weighted digraph.
Impossible.
possible , impossible, or an open research problem? Given a binary heap of N distinct comparable keys, create a binary search tree on the same set of N keys, using at most 2N compares.
Impossible. Given a binary heap of N distinct comparable keys, create a binary search tree on the same set of N keys, using at most 2N compares. This would violate the sorting lower bound. To see why, recall that you can construct a heap from N keys using at most 2N compares. Then, you could use the (hypothetical algorithm for creating a BST from the heap using 2N compares. Finally, an inorder traversal of the BST yields the keys in sorted order, using no extra compares. Thus, we could sort using at most 4N compares.
possible , impossible, or an open research problem? Given a binary heap on N distinct keys, build a BST containing those keys using ∼ 17N compares in the worst case.
Impossible. Recall that we can build a heap on any N keys with at most 2N compares. If we could then convert this heap into a BST with an additional ∼17N compares, then we could sort the keys by doing an inorder traversal of the BST. That is, we could sort using only ∼ 19N compares, which would violate the ∼ N log_2 N sorting lower bound.
possible , impossible, or an open research problem? Design a compare-based algorithm to merge two sorted arrays, each of length N/2, into a sorted array of length N that makes ∼1/2 N compares in the worst case.
Impossible.If you could do this, then the number of compares in mergesort would satisfy the recurrence C(N) = 2C(N/2)+1/2N, whose solution is C(N) ∼1/2N log_2 N. This compare-based sorting algorithm would violate the ∼ N log_2 N sorting lower bound.
Sort a list of keys which are already nearly in sorted order
Insertion sort
Suppose that your hash function does not satisfy the uniform hashing assumption. What consequences there could be?
It can result in a separate-chaining hash table having some very long chains and a linearprobing hash table having some very large clusters. Either of these situations can lead to poor (e.g., linear-time) performance for insert, search hit, and search miss. A linear-probing hash table can never become 100% full because it would be resized before this happened.
Compress an input stream, using a symbol table.
LZW
Suppose that you wish to sort a singly linked list of N Comparable items. Which algorithm would you choose and why? For your algorithm, describe its (i) memory usage, beyond the space required to represent the linked list, (ii) average asymptotic number of compares, and (iii) whether or not the algorithm is stable.
Mergesort O(log N) O(N log N) Y
BST. describe the order of growth of the height of an N-node tree in the worst case
N
Max number of probes to search for a key in a double hashing table with N key-value pairs. Worst case
N
quick-union with path compression. describe the order of growth of the height of an N-node tree in the worst case
N
Height of a BST with N keys. Worst case
N An unbalanced BST can have height proportional to N
Number of comparisons to quicksort N equal keys using 3-way quicksort. Worst case
N If all the keys are equal, 3-way quicksort will terminate after a single partioning step
Time to iterate over the keys in a BST using inorder traversal. Worst case
N Traversing a tree using { inorder, preorder, postorder, levelorder } takes linear time.
Number of comparisons to quicksort N equal keys using our standard version of quicksort. Worst case
N log N The Sedgewick partitioning algorithm stops on equal keys. As a result, each partitioning step will create two subproblems of equal size, just like mergesort.
Number of equality tests to insert N keys into an empty linear probing hash table of size 2N. Worst case
N2 If all keys hash to the same bin, the ith insertion will take time proportional to i.
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for BST
O(N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for BST with root insertion
O(N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for QU with path compression
O(N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for LLRBTree
O(log N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for heap ordered complete tree
O(log N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for randomized BST
O(log N)
Describe the guaranteed difference in the distance to the root for any two node in the tree, using worst case guarantee for weighted QU
O(log N)
possible , impossible, or an open research problem? Design a practical, in-place, stable, sorting algorithm that guarantees to sort any array of N comparable keys in at most ∼ N lg N compares.
Open
possible , impossible, or an open research problem? Given any array of N distinct integers, determine whether there are three integers that sum to exactly zero in time proportional to N^1.5
Open
Possible, impossible or open? Given an undirected graph, determine if there exists a path of length V − 1 with no repeated vertices in time proportional to EV in the worst case
Open. This is the Hamilton-Path problem, which is NP-complete. So, unless P = NP, there does not exist a polynomial-time algorithm for Hamilton-Path, but this is unknown.
Possible, impossible or open? Given an edge-weighted graph with positive edge weights, find a spanning tree that maximizes the product of the weights of the edges participating in the spanning tree in time proportional to E + V .
Open. Using the same log trick, this is equivalent to finding an MST. There is no known linear time algorithm of the problem.
Possible, impossible or open? Given an edge-weighted graph with positive edge weights and two distinguished vertices s and t, find a simple path (no repeated vertices) between s and t that maximizes the sum of the weights of the edges participating in the path in time proportional to E V
Open. Using the same log trick, this is equivalent to finding the longest path in a graph, which is NP-complete
String symbol table implementation. Find the value associated with a given string key in the data structure.
Ordered array, Red-black BST, Separate-chaining hash table, Ternary search trie
String symbol table implementation. Find the smallest string key in the data structure that is greater than or equal to a given string.
Ordered array, Red-black BST, Ternary search trie
String symbol table implementation. Find the smallest string key in the data structure.
Ordered array, Red-black BST, Ternary search trie
possible , impossible, or an open research problem? Given any array of N distinct integers, determine whether there are three integers that sum to exactly zero in time proportional to N^2
Possible
possible , impossible, or an open research problem? Given any array of N keys containing three distinct values, sort it in time proportional to N and using only a constant amount of extra space.
Possible
possible , impossible, or an open research problem? Given any left-leaning red-black BST containing N keys, find the largest key less than or equal to a given key in logarithmic time
Possible
possible , impossible, or an open research problem? Implement a FIFO queue with a constant amount of memory plus two LIFO stacks, so that each queue operation uses a constant amortized number of stack operations
Possible
possible , impossible, or an open research problem? Determine whether there are any intersections among a set of N axis-aligned rectangles in N log N time in the worst case
Possible. Determine whether there are any intersections among a set of N axis-aligned rectangles in N log N time. This was done in the geometric applications of BST lecture.
possible , impossible, or an open research problem? Find the kth smallest key in a left-leaning red-black BST in logarithmic time in the worst case.
Possible. Find the kth smallest key in a left-leaning red-black BST in logarithmic time. This is the select operation in an ordered symbol table.
possible , impossible, or an open research problem? Given an array a[] of N ≥ 2 distinct comparable keys (not necessarily in sorted order) with a[0] < a[N-1], find an an index i such that a[i] < a[i+1] in logarithmic time.
Possible. Given an array a[] of N ≥ 2 distinct comparable keys (not necessarily in sorted order) with a[0]<a[N− 1], find an an index i such that a[i] < a[i + 1] in logarithmic time. Use the following algorithm, similar to binary search. Maintain the invariant that a[i] <a[j]; initially i = 0 and j = N − 1. Pick mid = (i +j)/2. There are three cases - if j = i + 1, return i - else if a[mid] < a[j], then set i = mid - else if a[mid] > a[j], then set j = mid
Possible, impossible or open? Design an algorithm that compresses at least half of all 10,000-bit messages by one (or more) bits.
Possible. If the input has exactly 10000 bits and it starts with a 1, encode it by removing the leading 1; otherwise prepend 10000 1s to the input.
possible , impossible, or an open research problem? Implement a FIFO queue using a resizing array, in constant amortized time per operation.
Possible. Implement a FIFO queue using a resizing array, in constant amortized time per operation.
possible , impossible, or an open research problem? Find two strings in Java that are not equal but have the same hashCode()
Possible. In Java, hashCode() returns a 32-bit integer, so there are only 232 possible values. Since there are infinitely many different strings, an infinite number of strings share the same hash code. Moreover, since the formula for computing a string hash code is fixed, it's easy to find pairs of strings that have the same hash code, such as "Aa" and "BB".
Possible, impossible or open? Given an array of N integers between 0 and R − 1, stably sort them in time proportional to N + R in the worst case
Possible. Key-indexed counting accomplishes this.
possible , impossible, or an open research problem? Design a stable compare-based sorting algorithm that sorts any array of N comparable keys using ∼ N log_2 N compares in the worst case
Possible. Mergesort is such an algorithm.
Possible, impossible or open? Given an array a of N 64-bit integers, determine whether there are two indices i and j such that ai + aj = 0 in time proportional to N.
Possible. Radix sort the 64-bit integers; maintain two scanning pointers, one that indexes negative integers and goes from left to right and one that indexes positive integers and goes from right to left, checking for integers and their negations.
Possible, impossible or open? Given an array of N strings over the DNA alphabet {A, C, T, G}, determine whether all N strings are distinct in time linear in the number of characters in the input.
Possible. Radix sort the strings; then look at consecutive entries in the sorted array.
Possible, impossible or open? Given an array a of N 64-bit integers, determine whether there are two indices i and j such that ai = −aj in time proportional to N in the worst case.
Possible. Sort the integers in linear time, e.g., using LSD radix sort. Then, scan a pointer i from left to right and a pointer j from right to left. Compare ai + aj with 0: if equal, then done; if less, then increment i; if greater, then decrement j.
possible , impossible, or an open research problem? Stably sort a singly linked list of N comparable keys using only a constant amount of extra memory and ∼ N log_2 N compares.
Possible. Stably sort a singly linked list of N comparable keys using only a constant amount of extra memory and ∼ N log_2 N compares. Merging two sorted linked lists of total length N can be done with at most N compares and constant extra space. Bottom-up mergesort avoids extra memory association with the function-call stack.
possible , impossible, or an open research problem? Given a binary search tree (not necessarily balanced) on N distinct keys, build a binary heap containing those N keys using ∼ 17N compares in the worst case.
Possible. The reverse of an inorder traversal yields the keys in reverse order, which is heap ordered. That is, we can do it with 0 compares.
possible , impossible, or an open research problem? Implement a union-find data type so that all operations (except construction) take logarithmic time in the worst case.
Possible. The weighted quick-union data type achieves logarithmic time per union,find, and connected operation.
Possible, impossible or open? Given a flow network and a mincut in that flow network, find a maxflow in time proportional to E + V .
Possible. There is no known linear-time reduction from maxflow to mincut
possible , impossible, or an open research problem? Given a sorted array of N keys (not necessarily distinct), find the number of keys equal to a given query key using ∼ 2 log_2 N compares in the worst case.
Possible. This can be accomplished by two binary searches: one to find the first key in the array equal to the query key and one to find the last key in the array equal to the query key (as you did on the autocomplete assignment).
Possible, impossible or open? Given a digraph where each edge is colored black or orange and two vertices s and t, find a path from s to t that uses the fewest number of black edges in time proportional to E + V in the worst case.
Possible. This can be solved by a modified version of breadth-first search, where the vertices discovered by following black edges are put at the back of the queue (as usual) and the vertices discovered by following orange edges are put at the front of the queue.
Possible, impossible or open? Given an edge-weighted DAG with positive edge weights and two vertices s and t, find a path from s to t that maximizes the product of the weights of the edges participating in the path in time proportional to E + V .
Possible. This is equivalent to finding the shortest path from s to t using weights = -log of the original weights. Since the digraph is a DAG, this can be done in linear time.
Possible, impossible or open? Given an array of N integers between 0 and R^2 − 1, stably sort them in time proportional to N + R.
Possible. Treat each integer as a string of length 2 over an alphabet of size R. Sort the resulting strings using LSD radix sort.
possible , impossible, or an open research problem? Uniformly shuffle an array in linear time using only constant memory (other than the input array), assuming access to a random number generator.
Possible. Uniformly shuffle an array in linear time using only constant memory (other than the input array), assuming access to a random number generator. The Knuth shuffle accomplishes this.
Possible, impossible or open? Given an edge-weighted digraph in which all edge weights are either 1 or 2 and two vertices s and t, find a shortest path from s to t in time proportional to E + V .
Possible. You can solve using BFS. For each edge v → w that has weight 2, add a vertex x and replace the edge by the two edges v → x and x → w
Possible, impossible or open? Given a digraph, find a directed cycle that is simple (if one exists) in time proportional to E + V . A simple cycle is a cycle that has no repeated vertices other than the requisite repetition of the first and last vertex
Possible. You can use DFS to find a (simple) directed cycle.
Sort a large list of keys in roughly random order
Quicksort
You are managing the accounts for BigIBankCo, and have an array of customers together with their balances. You would like to rearrange the array such that the richest customers (those with balances greater than $1 million) are grouped at the beginning, with everyone else at the end. Describe an algorithm for performing this task in linear time, and using only constant extra memory. Adhering to the spirit of code reuse, adapt an algorithm from class and describe only the changes you would make.
Quicksort partitioning (but instead of using the rightmost element, use the value 1 million, swapping all keys strictly greater than the value to the left).
why you'd use one instead of the other? Red-black tree vs Ternary search trie
RBT: arbitrary Comparable keys, worst-case guarantee TST: faster for string keys, longest prefix match
why you'd use one instead of the other? Red-black tree vs Hash table
RBT:performance guarantee,range search Hash Table: O(1) average case
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. If the weights of all edges in G are increased by 17, then any MST in G is an MST in the modified edge-weighted graph.
True
String symbol table implementation. Associate a value with a string key.
Red-black BST, Separate-chaining hash table, Ternary search trie
String symbol table implementation. Delete a string key (and its associated value) from the data structure.
Red-black BST, Separate-chaining hash table, Ternary search trie
Maintain a symbol table where keys are long strings.
TST
String symbol table implementation. Find the string key in the data structure that is the longest prefix of a given string.
Ternary search trie
String symbol table implementation. How many string keys in the data structure starts with a given prefix?
Ternary search trie
How to recognize Shellsort?
The file is 4- and 13-sorted
How to recognize MSD?
The strings are sorted on their first character
Why does standard quicksort partitioning stop the partitioning scans on keys equal to the partitioning item?
To avoid quadratic running time.
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights. If the weights of all edges leaving s are increased by 17, then any shortest path from s to t in G is a shortest path in the modified edge-weighted digraph.
True
True or False? Let G be any simple graph (no self-loops or parallel edges) with positive and distinct edge weights.The MST of G is unique
True
True or False? The height of a TST is dependent on the size of the alphabet
True
True or False? Union-find is preferable to DFS for connectivity when edge insertion must be supported.
True
True or False? With DFS, we can support constant-time connectivity queries in an undirected graph, using linear space and linear preprocessing time.
True
True or false. A single key can be involved in as many as ∼ N compares when mergesorting an array containing N distinct keys.
True
True or false. Any two items are compared with one another no more than once during mergesort
True
True or false. Every exchange made by the Insertion Sort decreases the number of inversions of the sequence by exactly 1.
True
True or false. When mergesorting an array of N keys, the number of calls to merge() is ∼ N. (Recall that merge() is called only on subarrays of length 2 or more.)
True
true or false. The subtree rooted at any node of a 2-3 tree is itself a 2-3 tree.
True.
true or false. The order of growth of the total number of compares to insert N distinct keys in descending order into an initially empty max-oriented binary heap is N.
True. Since the keys are inserted in descending order, each insertion (other than the first) takes only 1 compare and 0 exchanges to swim it up from the bottom.
true or false. A 3-heap is an array representation (using 1-based indexing) of a complete 3-way tree, where the key in each node is greater than (or equal to) its children's keys. In the worst case, the number of compares to insert a key in a 3-heap containing N keys is ∼ 1 log_3 N.
True. The height of a complete ternary tree on N keys is ∼ log3 N. Inserting a key into a 3-way heap involves at most one compare and exchange per node on the path from a leaf to the root.
true or false. The height of any left-leaning red-black BST with N keys is always between ∼ 1 log_2 N and ∼ 2 log_2 N.
True. This is a basic propery of red-black BSTs.
How to recognize 3-way radix quicksort?
after 3-way partitioning, all smaller keys are in the top piece, all larger keys are in the bottom piece, and all keys that begin with j are in the middle piece.
How to recognize Quicksort?
after partitioning, all smaller keys are in the top piece, all smaller keys are in the bottom piece.
What is "averaging cost over multiple operations"?
amortization
What is "an unordered collection"?
bag
chaining or linear probing. Less wasted space.
linear probing
symbol table : BST :: priority queue :______
binary heap
chaining or linear probing. Easier to implement delete.
chaining
chaining or linear probing. Performance degrades gracefully
chaining
We are interested in the problem of finding a pair of duplicate elements in an array containing N unsorted integers. We use a hash table. We iterate over the array. For each element, we check if it is contained in the hash table: if it is not, we add it to the hash table; if it is, we have detected a pair of duplicates (and we may stop). Provide the order of growth of the best case run time (under the uniform hashing assumption)
constant
We are interested in the problem of finding a pair of duplicate elements in an array containing N unsorted integers. We use two nested loops, to consider every pair of elements of the array. For each pair, we check to see if the elements are identical (and stop iterating over the pairs as soon as we have found a pair of duplicates). Provide the order of growth of the best case run time (under the uniform hashing assumption)
constant
easy or impossible?Build a binary heap containing N keys using ∼ 2N compares (where the array of keys are given to you in arbitrary order).
easy. This is achieved in the first phase of heapsort. See Sedgewick Property 9.4.
easy or impossible?Build a balanced BST containing N keys using ∼ 8N compares (where the array of keys are given to you in ascending order).
easy. You don't need any compares. Make the median element (a[N/2]) the root, and apply this idea recursively.
True or false. Every exchange made by the Selection Sort decreases the number of inversions of the sequence by exactly 1.
false
True or false. Every exchange made by the Shell Sort decreases the number of inversions of the sequence by exactly 1.
false
What is "a language mechanism that enables use of the same code for multiple types of data"?
generics
easy or impossible?Build a balanced BST containing N keys using ∼ 8N compares (where the array of keys are given to you in arbitrary order).
impossible. If you could do this, then an inorder traversal (which requires no extra compares) would yield the elements in sorted order. This would violate the sorting N lg N lower bound.
easy or impossible?Design a priority queue that does insert and delete-max in ∼ lg lg N compares per operation, where N is the number of items in the data structure.
impossible. If you had such a priority queue, you could insert N keys and delete-max them to get the keys in sorted order in O(N lg lg N) time. This would violate the sorting N lg N lower bound.
easy or impossible?Build a BST containing N keys that has height at most 1/2 lg N.
impossible.Any binary tree on N nodes has height at least lg N
chaining or linear probing. The degradation caused by bad hash function tends to be amplified by a phenomenon called clustering.
linear probing
Describe the number of times that HeapSort assigns a value to an array entry, for randomly ordered array of distinct values
linearithmic
A sorting algorithm is parsimonious if no pair of items is compared more than once.Which sorting algorithm is parsimonious?
insertion sort and top-down mergesort are parsimonious
What is "code that keeps track of the process of returning each item in a collection to a client"?
iterator
A programmer building a symbol-table with single-character keys uses a bad hash function where keys in the first half of the alphabet (A through M) hash to the value 6 and keys in the second half of the alphabet (N through Z) hash to the value 9. Suppose that the same programmer has the same problem with N keys (half the keys hash to the value 6 and the other half hash to the value 9). What is the average time for a search hit with linear probing when searching for a random key?
linear
A programmer building a symbol-table with single-character keys uses a bad hash function where keys in the first half of the alphabet (A through M) hash to the value 6 and keys in the second half of the alphabet (N through Z) hash to the value 9. Suppose that the same programmer has the same problem with N keys (half the keys hash to the value 6 and the other half hash to the value 9). What is the average time for a search hit with separate chaining when searching for a random key?
linear
Describe the number of times that SelectionSort assigns a value to an array entry, for randomly ordered array of distinct values
linear
We are interested in the problem of finding a pair of non-duplicate elements in an array containing N unsorted integers. We use a hash table. We iterate over the array. For each element, we check if it is contained in the hash table: if it is not, we add it to the hash table; if it is, we have detected a pair of duplicates (and we may stop). Provide the order of growth of the best case run time (under the uniform hashing assumption)
linear
chaining or linear probing. Better cache performance.
linear probing
We are interested in the problem of finding a pair of duplicate elements in an array containing N unsorted integers. We sort the elements using quicksort (1 pivot, first element is pivot, no 3-way partitioning). Once the array is sorted, the duplicates contiguous, next to each other, so we simply iterate to find two adjacent elements that are identical (and stop iterating as soon as we have found a pair of duplicates). Provide the order of growth of the best case run time (under the uniform hashing assumption)
linearithmic
We are interested in the problem of finding a pair of non-duplicate elements in an array containing N unsorted integers. We sort the elements using quicksort (1 pivot, first element is pivot, no 3-way partitioning). Once the array is sorted, the duplicates contiguous, next to each other, so we simply iterate to find two adjacent elements that are identical (and stop iterating as soon as we have found a pair of duplicates). Provide the order of growth of the best case run time (under the uniform hashing assumption)
linearithmic
BST. describe the order of growth of the height of an N-node tree in the best case
log N
Heap-ordered complete tree. describe the order of growth of the height of an N-node tree in the best case
log N
Heap-ordered complete tree. describe the order of growth of the height of an N-node tree in the worst case
log N
Left-leaning red-black tree. describe the order of growth of the height of an N-node tree in the best case
log N
Left-leaning red-black tree. describe the order of growth of the height of an N-node tree in the worst case
log N
Max function call stack depth to mergesort N items. Worst case
log N
Max height of a WQUPC (weighted quick union with path compression) tree with N items. Worst case
log N
Max height of a binary heap with N items. Worst case
log N
Max height of red black tree with N items. Worst case
log N
weighted quick-union. describe the order of growth of the height of an N-node tree in the worst case
log N
Height of a binary heap with N keys. Worst case
log N Binary heaps are perfectly balanced by definition.
What is "when an unused memory reference cannot be reclaimed by the system"?
loitering
A programmer building a symbol-table with single-character keys uses a bad hash function where keys in the first half of the alphabet (A through M) hash to the value 6 and keys in the second half of the alphabet (N through Z) hash to the value 9. Suppose that the same programmer has the same problem with N keys (half the keys hash to the value 6 and the other half hash to the value 9). What is the total time to build the table with linear probing?
quadratic
Describe the number of times that Insertion Sort assigns a value to an array entry, for randomly ordered array of distinct values
quadratic
Give the order of growth of the running times of the Insertion sort sorting algorithm for arrays that are in reverse order.
quadratic
Give the order of growth of the running times of the Selection sort sorting algorithm for arrays that are already in order
quadratic
Give the order of growth of the running times of the Selection sort sorting algorithm for arrays that are in reverse order.
quadratic
We are interested in the problem of finding a pair of non-duplicate elements in an array containing N unsorted integers. We use two nested loops, to consider every pair of elements of the array. For each pair, we check to see if the elements are identical (and stop iterating over the pairs as soon as we have found a pair of duplicates). Provide the order of growth of the best case run time (under the uniform hashing assumption)
quadratic
A programmer building a symbol-table with single-character keys uses a bad hash function where keys in the first half of the alphabet (A through M) hash to the value 6 and keys in the second half of the alphabet (N through Z) hash to the value 9. Suppose that the same programmer has the same problem with N keys (half the keys hash to the value 6 and the other half hash to the value 9). What is the total time to build the table with separate chaining ?
quadratic (need to check for duplicates)
What is "a way to handle overflow in stacks and queues"?
resizing
MSD radix sort : R-way trie :: 3-way radix quicksort :______
ternary search trie
How to recognize Insertion?
the algorithm has sorted the first 12 strings, but hasn't touched the remaining 22 strings.
How to recognize Mergesort?
the algorithm has sorted the first 17 strings and the last 17 strings. One final merge will put the strings in sorted order.
How to recognize Heapsort?
the first phase of heapsort puts the keys in reverse order in the heap
How to recognize Selection?
the smallest 15 strings are in their final sorted order
How to recognize LSD?
the strings are sorted on their last character
What is "object version of a primitive type"?
wrapper
Min height of a weighted quick union tree with N items.
∼ 1
Max height of left-leaning red-black BST with N keys.
∼ 2 lg N
Max height of a 2-3 tree with N keys
∼ lg N
Max height of a binary heap with N keys
∼ lg N
Max height of a weighted quick union tree with N items.
∼ lg N
Min height of a binary heap with N keys
∼ lg N
Min height of left-leaning red-black BST with N keys.
∼ lg N
Min height of a 2-3 tree with N keys.
∼ log_3 N