This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COT5405 Analysis of Algorithms Midterm Solutions March 12, 2008 1. Graded by Manna T ( n ) = T ( n ) + 1 = T ( n 1 2 1 ) + 1 = T ( n 1 2 2 ) + 2 = ... = T ( n 1 2 i ) + i . Assume n 1 2 i = c = some small constant such that T ( c ) = constant. Thus, T ( n ) = T ( n 1 2 i )+ i = T ( c )+ i = O ( i ). Now, since c 2 i = n , log n = 2 i log c , which implies i = log log n log log c = O (log log n ). Therefore, T ( n ) = O (log log n ). Many of you gave answers like O (log n ) and ended up getting max 3040% marks. The reason penalties are harsh is because this problem was one where you could get the answer by simply computing mechanically no special intuition needed to be shown. In such cases, in order to get full credit, you must get it perfect. Moral of the story: easy come, easy go . 2. Graded by Ravi We get an O (1) amortized cost for Extractmin by using leftover credit from Insert. An insert of an element is charged O ( log n ), the depth of the heap, but the actual cost is only the number of levels the element has to percolate up. The rest of the credit (equal to the depth of the node at which the element is positioned) is used for achieving a O (1) amortized cost for Extractmin. We define a potential function based on the depth of nodes in the heap. Depth is the number of edges need to traversed to reach a root from node. Let H i be the heap after i th operation. For a node x let d i ( x ) be the depth of x in H i ....
View
Full
Document
 Fall '08
 UNGOR
 Algorithms

Click to edit the document details