Princeton Algorithms: Part 2 [week 7: Final Exam Part II]

来源:互联网 发布:程序员个人简介 编辑:程序博客网 时间:2024/06/05 08:26


Question Explanation

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

0: Original input
2: MSD radix sort after the first call to key-indexed counting
3: 3-way radix quicksort after the first partitioning step
2: MSD radix sort after the second call to key-indexed counting
1: LSD radix sort after 3 passes
1: LSD radix sort after 1 pass
1: LSD radix sort after 2 passes
3: 3-way radix quicksort after the second partitioning step
4: Sorted



Question Explanation

The correct answer is: A B B C D C D D


Below are the sorted cyclic suffixes and the next[] array:

i suffixes[i] t next[i]
-----------------------------
* 0 A ? ? ? ? ? ? D 1
1 B ? ? ? ? ? ? A 2
2 B ? ? ? ? ? ? B 3
3 C ? ? ? ? ? ? B 6
4 C ? ? ? ? ? ? D 7
5 D ? ? ? ? ? ? D 0
6 D ? ? ? ? ? ? C 4
7 D ? ? ? ? ? ? C 5

Since first = 0, the first character is A (the first character in row 0).

Since next[0] = 1, the second character is B (the first character in row 1).

Since next[next[0]] = 2, the third character is B (the first character in row 2).

Since next[next[next[0]]] = 3, the fourth character is C (the first character in row 3).




0 0
原创粉丝点击