判断题
Kruskal's minimum spanning tree algorithm implemented by disjoint set with union-by-rank strategy has O(∣E∣log∣E∣) time complexity. Further optimization by introducing path compression improves it to O(∣E∣α(∣E∣,∣V∣)) where α is the functional inverse of Ackermann's function.
答案是F
here the rank just means the height of a tree
这里的指的是Ackermann函数的逆
如何实现Kruskal 算法呢?
- 把所有的edge从小到大排序
- 取出最小的edge,在对应的set中find,如果find两侧的root是不一样的,那么就需要使这两个点执行一次union
- 不断进行第二步,直到所有的edge遍历完
我们可以做出算法复杂度分析,总共有E次边的探索。Union-by-height,树的高度约为logV。因此总的时间复杂度就是E log V。
如果加入了path compression,那么连续E次操作,树内元素最多是V,可以得到最终的时间复杂度即为O(∣E∣α(∣E∣,∣V∣))
The FirstChild-NextSibling representation of a tree is unique.
the answer is F
FirstChild-NextSibing并没有说明一定要选最左边的作为FirstChild,同样的,对于Sibling到底是哪一个点也是不在乎的。
{ 5,2,12,28,16,32,72,60 } cannot be the result after the second run of quick sort (assuming the pivot is chosen randomly).
the answer if F
第二趟run的时候,pivot左边的数组和右边的数组单独排序,如果pivot在边角,那么就只会有两个pivot存在。
这里pivot不在边角,应当存在3个pivot,但是只有两个pivot,所以这题是错的。
编程题
qsort里面的cmp的函数的强制要求接口形式是int cmp(const void * a, const void * b),如果不是这样子写的话,那么会在排序的时候出现问题(并且不会报错,十分麻烦)