Ch01 AVL
After merging two Leftist Heaps H1 and H2 of different NPL's, the NPL of the resulted Leftist Heap will be no more than max(NPL of H1, NPL of H2)
F。一个左偏树差一个点满,另一个左偏树只有一个节点,则插入后增加。实际上应有 。 Answer
There exists an AVL tree of depth 6 (the depth of the root is 0) containing 31 nodes.
F。设 为深度为 的 AVL 树的最小节点数,则:;;。 课件也有提到: Answer
Ch02 Red Black Tree & B+ Tree
Insert into an initially empty 2-3 tree (with splitting), and then delete 7. Which one of the following statements is FALSE about the resulting tree?
- A. there are 3 leaf nodes
- B. 13 and 15 are in the same node
- C. the parent of the node containing 18 has 3 children
- D. the first key stored in the root is 11
B。如果叶子数量小于 2,需要一直向上寻求合并。 Answer
In a red-black tree, the number of internal nodes in the subtree rooted at x is no more than where is the black height of x. (T or F)
F。应为 。因为 对红黑树成立。 Answer
Ch04 Leftist Heap & Skew Heap
By definition, for a light node in a skew heap, the number of descendants of 's right subtree is no more than 1/2 of the number of descendants of .
F。如果刚好等于的话根据定义应该归为重节点。考虑左子树为空右子树大小为 1 的情况。 Answer
Ch05 Binomial Queue
For a binomial queue, ___ takes a constant time on average.
- A. merging
- B. find-max
- C. delete-min
- D. insertion
D。因为是均摊复杂度,考虑进位次数的均摊,可以证明插入操作是均摊 的。 Answer
Ch06 Backtracking
For the Turnpike reconstruction algorithm of points, assuming that the distance set is maintained as an AVL tree, the running time is if no backtracking happens.
T。每一层都需要 (其实总共都有 对距离要删除)。 Answer
Given the following game tree, the red node will be pruned with - pruning algorithm if and only if ___.
- A.
- B.
- C.
- D.
D。其实这里可以剪枝的理由就是,无论其值多小,只能让父亲从 9 变成更小的值。但是如果这里整棵树的根节点已经大于等于 9,那么即使让他变的比 9 更小也已经没有意义,所以可以删除。 Answer
Ch07 Divide and Conquer
Recall that in the merge sort, we divide the input list into two groups of equal size, sort them recursively, and merge them into one sorted list. Now consider a variant of the merge sort. In this variant, we divide the input list into groups of equal size, where is the input size. What is the worst case running time of this variant? (You may use the fact that merging sorted lists takes where is the total number of elements in these lists.)
- A.
- B.
- C. None of the other options is correct
- D.
B。 Answer
Recall that, to solve the cloest pair problem, the first step of the divide-and-conquer algorithm divides the point set into and according to hte x-coordinate. Is the following statement true or false?
- In the combine step of this algorithm, it is always to find the closest pair with one point in and the other in .
F。只检查了是否会小于 ,有可能最小的一对比这个大,直接没检查过。 Answer
Consider the following pseudo-code.
strang():
- if then return
- strange()
- strange()
- for to :
- for to :
- print()
- strange()
- strange()
What is the running time of this pseudo-code? Your answer should be as tight as possible. (You may assume that is a power of 2.)
- A. None of the order options is correct.
- B.
- C.
- D.
D。
应用等比数列求和公式可证 。 Answer
Consider the following pseudo-code.
strange()
- if then return
- strange()
- for to :
- for to :
- print()
- strange()
What is the running time of this pseudo-code? Your answer should be as tight as possible. (You may assume that is a power of 2.)
- A. None of the order options is correct.
- B.
- C.
- D.
B。可以直接应用主定理。 Answer
When solving a problem with input size by divide and conquer, if at each stage the problem is divided into sub-problems of equal size , and the conquer step takes to form the solution from the sub-solutions, then the overall time complexity is ___.
- A.
- B.
- C.
- D.
A。是直接应用主定理的结果,,。 Answer
Is this asymptotic upper bound for the following recursive is correct?
- . Then .
T。 可以直接做: 也可以归纳法: 注意 与 是小于零的常数。 Answer
Ch10 NP
If and , then . (T/F)
T。 可能还是 问题,但注意 问题都是 问题。 Answer
Suppose is a problem in , but not necessarily NP-complete. Which of the following is FALSE?
- A. A polynomial-time algorithm for SAT would sufficiently imply a polynomial-time algorithm for .
- B. A polynomial-time algorithm for would sufficiently imply a polynomial-time algorithm for SAT.
- C. If , then .
- D. If is NP-hard, then is NP-complete.
B。A 选项就是说能在多项式时间内解决 SAT 问题,即 ,这样任何 NP 问题都能在多项式时间复杂度内解决,故自然存在对 的多项式复杂度解。但是 B 选项对于问题 就没有这一性质。 Answer
The following problem is in co-NP. (T/F)
- Given a positive integer , is a prime number?
T。;。 Answer
Ch11 Approximation
Assume that you are a real world Chinese postman, which have learned an awesome course "Advanced Data Structures and Algorithm Analysis" (ADS). Given a 2-dimensional map indicating positions of your post office and all the addresses you must visit, you'd like to find a shortest path starting and finishing both at your post office, and visit all the addresses at least once in the circuit. Fortunately, you have a magic item "Bamboo copter & Hopter" from "Doraemon", which makes sure that you can fly between two positions using the directed distance (or displacement).
However, reviewing the knowledge in the ADS course, it is an problem! Wasting too much time in finding the shortest path is unwise, so you decided to design a algorithm as follows, to achieve an acceptable solution.
Compute a minimum spanning tree T connecting all the addresses.
Regard the post office as the root of T.
Start at the post office.
Visit the addresses in order of a _____ of T.
Finish at the post office.
There are serveral methods of traversal which can be filled in the blank of the above algorithm. Assume that , how many methods of traversal listed below can fulfill the requirement?
- Level-Order Traversal
- Pre-Order Traversal
- Post-Order Traversal
2。pre-order 和 post-order 都是可行的。因为最小生成树的边权和一定小于 OPT,而这两种 travelsal 每条边最多走两次,所以是一个 2-approximation。 Answer
As we know there is a 2-approximation algorithm for the Vertex Cover problem. Then we must be able to obtain a 2-approximation algortithm for the Clique problem, since the Clique problem can be polynomially reduced to the Vertex Cover problem. (T/F)
F。虽然这两个问题是可以互相规约的,但是计算近视率时除的最优解不同,稍微构造一下即可推翻: Answer
Ch12 Local Search
Max-cut problem: Given an undirected graph with positive integer edge weights , find a node partition such that , the total weight of edges crossing the cut, is maximized. Let us define to be the neighbor of that can be obtained from by moving one node from to , or one from to . We only choose a node which, when flipped, increases the cut value by at least . Then which of the following is true?
- A. Upon the termination of the algorithm, the algorithm returns a cut so that , where is an optimal partition.
- B. The algorithm terminates after at most flips, where is the total weight of edges.
- C. Upon the termination of the algorithm, the algorithm returns a cut so that .
- D. The algorithm terminates after at most flips.
A。直接代入公式: Answer
Ch14 Parallel
Which one of the following statements about the Maximum Finding is False?
- A. Parallel random sampling algorithm can run with work load.
- B. Common CRCW can be used to solve the access conflicts in this problem.
- C. It can be solved by summation algorithm with time complexity being .
- D. There exists parallel algorithm solving the problem in constant time.
A。 Answer
When we solve the summation problem via designing the parallel algorithms, we shorten the aasymptotic time complexity but take more asymptotic work loads comparing with the sequential algorithms.
F。不一定是 more。 Answer
There is an array , . If we use Balanced Binary Trees Parallel Algorithm to calculate the Prefix-Sum of . Define , where is the rightmost descendant leaf of node . Node indicates the -th node in height . For example, the root is node and leaves are node . The value of is
- A.
- B.
- C.
- D.
A。相当于 。 是对应子树和, 是子树最右端节点前缀和。 的过程从下到上并行合并, 的过程从上到下。 Answer
Ch15 External Sorting
If only one tape drive is available to perform the external sorting, then the tape access time for any algorithm will be (T/F)
T。考虑寻道时间从 变成 。 Answer
Given 100,000,000 records, each 256 bytes, and an internal memory size of 128MB, if a simple 2-way merge is used, how many passes do we have to do?
- A. 10
- B. 9
- C. 8
- D. 7
B。pass 数量是 log (runs 数量)+1(根据课件公式) Answer
We have 4 tapes for 3-way external merge sorting. How shall we distribute 31 runs into 3 tapes, such that the total number of passes is minimized?
- A. 15 runs on Tape 1, 9 runs on Tape 2, and 7 runs on Tape 3.
- B. 13 runs on Tape 1, 11 runs on Tape 2, and 7 runs on Tape 3.
- C. 13 runs on Tape 1, 10 runs on Tape 2, and 8 runs on Tape 3.
- D. 11 runs on Tape 1, 10 runs on Tape 2, and 10 runs on Tape 3.
B。三阶斐波那契数列为:0,0,1,1,2,4,7,13,24,我们选择 ,,,可以得到一组划分为 7+11+13=31,刚好就是我们想要的总数。如果不能恰好对上的话,应选第一组大于等于的。 Answer
Suppose we have the internal memory that can handle 12 numbers at a time, and the following two runs on the tapes:
Run 1: 1, 3, 5, 7, 8, 9, 10, 12 Run 2: 2, 4, 6, 15, 20, 25, 30, 32
Use 2-way merge with 4 input buffers and 2 output buffers for parallel operations. Which of the following three operations are NOT done in parallel?
- A. 1 and 2 are written onto the third tape; 3 and 4 are merged into an output buffer; 6 and 15 are read into an input buffer
- B. 3 and 4 are written onto the third tape; 5 and 6 are merged into an output buffer; 8 and 9 are read into an input buffer
- C. 5 and 6 are written onto the third tape; 7 and 8 are merged into an output buffer; 20 and 25 are read into an input buffer
- D. 7 and 8 are written onto the third tape; 9 and 15 are merged into an output buffer; 10 and 12 are read into an input buffer
D。大概是懂了,好像又没懂,求大哥评论区教教。 Answer
Ex01 Amortized Analysis
A -nodes AVL tree performs insertion or deletion in the worst case that costs , , respectively, where are constants. Now, we start from an empty tree, perform a sequence of n insertions or deletions in the AVL tree. To analysis the amortized cost per insertion or deletion, we define a potential function . What is the amortized cost per insertion or deletion?
- A. for insertion, for deletion
- B. for insertion, for deletion
- C. for insertion, for deletion
- D. for insertion, for deletion
A。简单版本的理解是如果一次操作的时间贡献为 ,势能贡献为 ( 可能为负数),那么这次的 amortized cost 为 ,或者直接用 potential method 的柿子: Answer
We have a binary counter of k bits. Each time we conduct an increment on the counter: and the cost of the increment is the number of bits we need to flip. For example, when , currently we have , after increment we have . Then this increment costs 1 because only 1 bit flips after increment. If we conduct the increment again, . Then this increment costs 3 because we flip 3 bits. Now we conduct n consecutive increments and estimate the total cost. Which of the following statements are TRUE?
- If the initial value of the counter is 0, the total cost is
- If the initial value of the counter is 0, the total cost is
- If n = , the total cost is
- If n = , the total cost is
- A. 2 and 4
- B. 2 and 3
- C. 1 and 3
- D. 1 and 4
C。对于 1,可以直接考虑每一位的反转次数。对于 3,考虑如果不从 开始可以用 的代价消除影响,然而有 ,所以有 。 Answer
In this problem, we would like to find the amortized cost of insertion in a dynamic table . Initially the size of the table is 1. The cost of insertion is if the table is not full. When an item is inserted into a full table, the table is expanded as a new table of size times larger. Then, we copy all the elements of the old table into this new table, and insert the item in the new table.
Let be the number of elements in the table , and be the total number of slots of the table. Let denote the table after applying the -th operation on .
Which of the following potential function can help us achieve amortized cost per insertion?
- A.
- B.
- C.
- D.
C。可以这样分析,设 。 现在让 ,所以有 。再由于 ,可得 。所以选 C。 Answer
Other Problems
Consider a bipartite graph . (Recall that a graph is bipartite if the vertex set of can be partitioned into and such that all the edges of have one endpoint in and the other in .) A matching in is a subset of such that no two edges in have a common vertex. A vertex cover is a subset of , where every edge in must have at least one endpoint in . Denote by the cardinality of a set . Which of the following statements is true?
- A. For a minimum vertex cover , .
- B. Exactly one of the other options is wrong.
- C. For any vertex cover and any matching , .
- D. For a minimum vertex cover and a maximum matching , .
A。对于 B,考虑一个不与其他点连边的孤立点,只会贡献 而不会贡献 。对于 C,D,可以利用二分图最大匹配=最小点覆盖分析。 Answer
Consider two disjoint sorted arrays and , we would like to compute the -th smallest element in the union of the two arrays, where . Please choose the smallest possible running time among the following options:
- A.
- B.
- C.
- D.
D。脑筋急转弯。注意到 都是 sorted,所以最后的复杂度肯定和 无关。 Answer