{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


cs320-2008-t2-midterm2-solution - CPSC 320 Sample Midterm 2...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CPSC 320 Sample Midterm 2 March 2009 [12] 1. Skip Lists [4] a. When we augment a skip list to support efficient Order-Statistics queries, we store a count value with each pointer of the skip list. What does count represent, and how is it used by SkipListSelect ? Solution : This value is the difference in rank (position) in the skip list between the node that contains the pointer, and the node the pointer points to. [4] b. How does algorithm UpdatedSkipListInsert use the Rank array filled by algorithm UpdatedSkipListSearch to recompute the count values associated with the pointers stored in the new node? Solution : It uses the Rank array to compute the ranks of the new node (that is, Rank[1] + 1 ), and the rank of the node the pointer points to (that is, Rank[lev] + count(Pointer[lev], lev) ). The count value we want will be the dif- ference of these two ranks. [4] c. When we analyzed the expected running time of algorithm SkipListSearch we looked at the path taken by the algorithm through the skip list “backwards”. That is, we analyzed the expected number of left moves of the reverse path (from the node we are searching for to the head of the skip list) on each given level, instead of analyzing the expected number of right moves on each level. Why? Solution : Because when going from right to left, we know the probability of going up ( p ) and the probability of going left ( 1 p ). These allow us to compute the expected number of left moves on level i . When we go from left to right, on the other hand, we do not know the probabilities of going down or right. [8] 2. Show the tree constructed by Dijkstra’s algorithm for the graph in the following figure, assuming that the first vertex added to the tree is vertex V 0 . Label each edge of your tree by a number that indicates the order in which the edges were added to the tree (so the first edge added will be labeled “1”, the second edge added will be labeled “2”, etc). Show the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}