


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Write the sentence āI understand the course policies." at the top of your solution to problem 1.
(a) List the nodes in Georgeās tree in the order visited by an inorder traversal. (b) Draw Georgeās tree.
A ( n ) = 10 A ( n/ 5 ) + n
B ( n ) = 2 B
n + 3 4
r n log n
ƶ log^10 n
ù ā 11
C ( n ) = 3 C ( n/ 2 ) + C ( n/ 3 ) + 5 C ( n/ 6 ) + n^2 D ( n ) = max 0 <k<n
( D ( k ) + D ( n ā k ) + n )
E ( n ) =
E ( n ā 1 ) E ( n ā 3 ) E ( n ā 2 )
[Hint: Write out the first 20 terms.]
(b) [5 pts] Sort the following functions from asymptotically smallest to asymptotically largest, indicating ties if there are any. Do not submit proofs ājust a sorted list of 16 functionsābut you should do them anyway, just for practice. Write f ( n ) g ( n ) to indicate that f ( n ) = o ( g ( n )), and write f ( n ) ā” g ( n ) to mean f ( n ) = Ī( g ( n )). We use the notation lg n = log 2 n.
n lg n
p n 3 n p lg n lg p n 3
p n p 3 n
3 lg^ n^ lg( 3 n ) 3 lg^
p n 3
p lg n p 3 lg^ n^ lg( 3
p n ) lg
p 3 n^
p lg( 3 n )
Top: A standard singly-linked list. Bottom: A corrupted singly linked list.
Describe an algorithm^1 that determines whether the linked list is corrupted or not. Your algorithm must not modify the list. For full credit, your algorithm should run in O ( n ) time, where n is the number of nodes in the list, and use O ( 1 ) extra space (not counting the list itself).
(^1) Since you understand the course policies, you know what this phrase means. Right?
? 6. [Extra credit] You may be familiar with the story behind the famous Tower of HanoĆÆ puzzle:
At the great temple of Benares, there is a brass plate on which three vertical diamond shafts are fixed. On the shafts are mounted n golden disks of decreasing size. At the time of creation, the god Brahma placed all of the disks on one pin, in order of size with the largest at the bottom. The Hindu priests unceasingly transfer the disks from peg to peg, one at a time, never placing a larger disk on a smaller one. When all of the disks have been transferred to the last pin, the universe will end.
Recently the temple at Benares was relocated to southern California, where the monks are considerably more laid back about their job. At the āTowers of Hollywoodā, the golden disks have been replaced with painted plywood, and the diamond shafts have been replaced with Plexiglas. More importantly, the restriction on the order of the disks has been relaxed. While the disks are being moved, the bottom disk on any pin must be the largest disk on that pin, but disks further up in the stack can be in any order. However, after all the disks have been moved, they must be in sorted order again.
The Towers of Hollywood. The sixth move leaves the disks out of order.
Describe an algorithm that moves a stack of n disks from one pin to the another using the smallest possible number of moves. Exactly how many moves does your algorithm perform? [Hint: The Hollywood monks can bring about the end of the universe considerably faster than their Benaresian counterparts.]