



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science; University: University of New Mexico; Term: Spring 2004;
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Jared Saia
University of New Mexico
Skip Lists
Any questions on the homework?
This
week
and
next,
you
can
get
one
extra
participation
there and want a check.check by going to section and informing Nate that you’re
1:50 TAPY 218Sections are Thursday 5:30-6:20 DSH 134 and Friday 1:00-
terial for finalGood chance to get info on hw, projects and to review ma-
Project will be due May 6th in class
Late projects will
not
be accepted
lateon time but will get no credit for a finished project turned inYou can get partial credit for an unfinished project turned in
Final will be May 11th 5:30-7:30pm in our regular classroom
Closed book,
but two pieces of paper and calculators are
allowed
operationsTechnically, not a BST, but they implement all of the same
analysis is subtleVery elegant randomized data structure, simple to code but
erations takeThey guarantee that, with high probability, all the major op-
(log
(^) n
) time
skip
list
is
basically
a
collection
of
doubly-linked
lists,
1 , L
2 ,... , L
x , for some integer
x
nodes are assumed to beEach list has a special head and tail node, the keys of these
MAXNUM and +MAXNUM re-
spectively
The keys in each list are in sorted order (non-decreasing)
−∞
+∞
1 2 3 4 5 6 7 8 9
0
−∞
+∞
1
6
7
9
0
−∞
+∞
1
6
7
3
−∞
+∞
1
7
−∞
+∞
7
−∞
+∞
p
is a constant between 0 and 1, typically
p
= 1
2, let rand()
while (rand()<= p){i = 2;Insert k in L_1, to the right of pLeftFirst call Search(k), let pLeft be the leftmost elem <= k in L_1 Insert(k){return a random value between 0 and 1
insert k in the appropriate place in L_i;
Deletion is very simple
First do a search for the key to be deleted
deletionthe bottom up, making sure to “zip up” the lists after theThen delete that key from all the lists it appears in from
number of levels to be aboutber of nodes of the previous level, so we expect the totalIntuitively, each level of the skip list has about half the num-
(log
(^) n
)
time in half except for a constant overheadSimilarly, each time we add another level, we cut the search
So after
(log
(^) n
) levels, we would expect a search time of
(log
(^) n
)
We will now formalize these two intuitive observations
For some key,
i , let
i
be the maximum height of
i
in the
skip list.
Q: What is the probability that
i ≥
2 log
(^) n
?
A: If
p
= 1
2, we have:
i ≥
2 log
(^) n
)
( 2 1 ) 2 log
(^) n
log
(^) n ) 2
n 2
Thus the probability that a particular key
i
achieves height
2 log
(^) n
is
n 1 2
What
is
the
probability
that
any
key
achieves
height
2 log
(^) n
?
A: We want
1
≥
2 log
(^) n
or
2
≥
2 log
(^) n
or
or
n
≥
2 log
(^) n
)
By a Union Bound, this probability is no more than
P (^) ( X
1
≥
k (^) log
(^) n
) +
2
≥
k (^) log
(^) n
) +
n
≥
k (^) log
(^) n
)
Which equals:
n
i=1 ∑
n 1 2
=
n
n 2
= 1
/n
This probability gets small as
n
gets large
ceeding 2 logIn particular, the probability of having a skip list of size ex-
(^) n
is
o (1)
If an event occurs with probability 1
o (1), we say that it
occurs
with high probability
Key Point:
The height of a skip list is
(log
(^) n
) with high
probability.
variables: A trick for computing expectations of discrete positive random
Let
be a discrete r.v., that takes on values from 1 to
n
n
i=1 ∑
i )
For every node
v
in the skip list Up(v) exists with probability
So for purposes of analysis, SLFBack is the same as
FlipWalk(v){the following algorithm:
while (v != L){
if (COINFLIP == HEADS)
v = Up(v);
else
v = Left(v);
the same as the expected number of tailsFor this algorithm, the expected number of heads is exactly
expected number of upward jumpsThus the expected run time of the algorithm is twice the
is Since we already know that the number of upward jumps
(log
(^) n
) with high probability, we can conclude that the
expected search time is
(log
(^) n
)