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: CPSC 320 Sample Midterm 2 March 2009  1. Skip Lists  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.  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 ), 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.  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.  2. Show the tree constructed by Dijkstras algorithm for the graph in the following figure, assuming that the first vertex added to the tree is vertex V . 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...
View Full Document
- Fall '10