Princeton Algorithms: Part 1 [Final Exam Part I]

来源:互联网 发布:雕刻大师软件 编辑:程序博客网 时间:2024/06/05 16:54

Explanation:

The correct answer is: 48 29 18 24

Here is the array to be searched after each compare:

12 18 24 29 40 41 45 48 49 65 70 73 77 84 91
48: 12 18 24 29 40 41 45 - - - - - - - -
29: 12 18 24 - - - - - - - - - - - -
18: - - 24 - - - - - - - - - - - -
24: - - - - - - - - - - - - - - -



Explanation:

The theoretical order-of-growth is N ^ (52/15) = 3.47

The empirical order-of-growth is N ^ (log_2 ratio)

log_2
N seconds ratio ratio
---------------------------------------
32 0.000 - -
64 0.003 - -
128 0.026 8.67 3.12
256 0.281 10.81 3.43
512 3.173 11.29 3.50
1024 35.897 11.31 3.50
2048 391.666 10.91 3.45
4096 4336.940 11.07 3.47



Explanation:

The answer is : N log N

The i loop iterates lg N times; the j loop iterates N times.





Explanation:

The correct answer is: 0 1 3 5 2 4 6

0: Original input
1: Selection sort after 12 iterations
3: Mergesort (top-down) just before the last call to merge()
5: Heapsort after heap construction phase
2: Insertion sort after 16 iterations
4: Quicksort (standard, no shuffle) after first partitioning step
6: Sorted


Explanation:

The correct answer is: F D D D D


Explanation:

The correct answer is: C C A A C C


Explanation:

The correct answer is: C A B B C A



Explanation:

The correct answer is: B B B B C B



Explanation:

The correct answer is: F F A F J F





0 0
原创粉丝点击