title: "一些作業錯題"
author: Sun-Wind
date: January 6, 2022
A graph with 30 vertices and 40 edges must have at most
twenty one connected component(s).
- 要計算最大連通分量,應該盡量先把邊湊完,然后后面的每一個頂點分別是一個獨立的連通分量
- 所以10 * 9 / 2 > 40 第一個連通分量用10個頂點,剩下20個頂點就是20個連通分量
- 最后加上第一個連通分量
Since the speed of a printer cannot match the speed of a computer, a buffer is designed to temperarily store the data from a computer so that later the printer can retrieve data in order. Then the proper structure of the buffer shall be a:
A.stack
B.queue
C.tree
D.graph
- 概念題
To build a heap from N records, the best time complexity is:
A.O(logN)
B.O(N)
C.O(NlogN)
D.O(N^2)
Heapify
從最后一個非葉子節點一直到根結點進行堆化的調整。如果當前節點小於某個自己的孩子節點(大根堆中),那么當前節點和這個孩子交換。Heapify是一種類似下沉的操作,HeapInsert是一種類似上浮的操作。
這種建堆的時間復雜度是O(N)
怎么找到第一個非葉子節點
根節點在數組中的索引為1,所以第一個非葉子節點的計算公式為: last_non_leaf = arr.length/2。
如果根節點在數組中的索引為0,那么第一個非葉子節點的計算公式為: last_non_leav = (arr.length - 2)/2
可以設最后一個非葉子節點位置為x,那么最后一個葉子節點一定是(2x+1) 或者(2x+2)中的一個,然后可以建立方程求解。
Which one of the following relations is correct about the extra space taken by heap sort, quick sort and merge sort?
A.heap sort < merge sort < quick sort
B.heap sort > merge sort > quick sor
C.heap sort < quick sort < merge sort
D.heap sort > quick sort > merge sort
空間復雜度堆排序O(1),快速排序O(logN),歸並排序O(N);
The average search time of searching a hash table with N elements is:
A.O(1)
B.O(logN)
C.O(N)
D.cannot be determined
這個題有點爭議,按照道理來講平均查找時間復雜度是O(1),如果有沖突的話可能會退化到O(N)
目前只能先記一下答案。如果說的有不對的地方大家可以在評論區指出
If a binary search tree of N nodes is complete, which one of the following statements is FALSE?
A.the average search time for all nodes is O(logN)
B.the minimum key must be at a leaf node
C.the maximum key must be at a leaf node
D.the median node must either be the root or in the left subtree
可能會出現最后一個節點沒有右子樹的情況
To sort { 8, 3, 9, 11, 2, 1, 4, 7, 5, 10, 6 } by Shell Sort, if we obtain ( 4, 2, 1, 8, 3, 5, 10, 6, 9, 11, 7 ) after the first run, and ( 1, 2, 3, 5, 4, 6, 7, 8, 9, 11, 10 ) after the second run, then the increments of these two runs must be __ , respectively.
A.3 and 1
B.3 and 2
C.5 and 2
D.5 and 3
哈希排序可以看上一篇博客
To delete X from a splay tree, the operations are: (1) Find X; (2)Remove X; (3) FindMin(T
R); and the last operation is:
A.Make T L the right child of the root of T R
B.Make T L the left child of the root of T R
C.Make T R the right child of the root of T L
D.Make T R the left child of the root of T L
Let T be a tree of N nodes created by union-by-size without path compression, then the minimum depth of T may be
A.1
B.logN
C.N−1
D.N/2
Given an integer sequence 25、84、21、47、15、27、68、35、20, after the Heapsort's initial heap building, this interger sequence is __.
A.47 20 21 25 84 27 68 35 15
B.15 21 20 25 84 27 68 35 47
C.15 20 21 25 84 27 68 35 47
D.25 15 20 47 35 21 68 84 27
Given an integer sequence 25、84、21、47、15、27、68、35、20, after the first run of the shell sorting by an increment 3, the integer sequence is __.
A.25 15 20 27 35 21 68 84 47
B.15 21 20 25 84 27 68 35 47
C.25 15 20 47 21 35 68 84 27
D.25 15 20 47 35 21 68 84 27
希爾排序可以看上一篇博客
One of the following algorithms: Selection sort, Shell sort, Insertion sort, is applied to sort the sequence (2, 12, 16, 88, 1, 5, 10)in ascending order. If the resulting sequences of the first two runs are (2, 12 , 16, 10, 1, 5, 88) and (2, 12, 5, 10, 1, 16, 88), then the algorithm must be ____.
A.Selection sort
B.Shell sort
C.Insertion sort
D.uncertain
For a graph, if each vertex has an even degree, we can find an Euler circuit that visits every vertex exactly once.
T F
Linear probing is equivalent to double hashing with a secondary hash function of Hash 2(k)=1 .
T F
Quadratic probing is equivalent to double hashing with a secondary hash function of Hash (k)=k.
T F
In a binary tree, if node A is a descendant of node B, A may precede B in the inorder traversal sequence.
T F
To prove the correctness of a greedy algorithm, we must prove that an optimal solution to the original problem always makes the greedy choice, so that the greedy choice is always safe.
T F
To sort N records by quick sort, the worst-case time complexity is Ω(NlogN).
T F