lec19 - Lecture 19 Self-organizing data structures lists...

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

View Full Document Right Arrow Icon
Page 1 of 36 CSE 100, UCSD: LEC 19 Lecture 19 Self-organizing data structures: lists, splay trees Data structures for multidimensional data: K-D trees The C++ Standard Template Library and Java Generics Final review Reading: Weiss, Ch. 4 and Ch. 12
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
Page 2 of 36 CSE 100, UCSD: LEC 19 Final exam Final exam time: Wed Dec 9 11:30am-2:00pm Location: lecture room Closed book, closed notes, no calculators. .. Bring something to write with, and picture ID Practice final is on line Final exam discussion topic on Webboard Exam review sessions will be: last lecture Coverage: All lectures, all assignments, corresponding sections of the textbook, and handouts
Background image of page 2
Page 3 of 36 CSE 100, UCSD: LEC 19 Self-organizing data structures The path-compression find algorithm for disjoint subsets does more than just find the label of the subset containing an item: it also modifies the disjoint subset structure so subsequent find operations will be faster Amortized analysis of path-compression find shows that in the worst case, any sufficiently long sequence of find operations will have very small (practically constant) time cost per operation ... so the additional work to compress the paths is worth it “in the long run” This idea of self-organizing data structures can be applied to all manner of data structures: lists, trees, hashtables, etc. We will look briefly at: self-organizing lists splay trees
Background image of page 3

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

View Full Document Right Arrow Icon
Page 4 of 36 CSE 100, UCSD: LEC 19 Self-organizing lists Worst-case time cost for searching a linked list is O(N) Assuming all keys are equally likely to be searched for, average case time cost for successful search in a linked list is also O(N) But what if all keys are not equally likely? Then we might be able to do better by putting keys that are more likely to be searched for at the beginning of the list. ..
Background image of page 4
Page 5 of 36 CSE 100, UCSD: LEC 19 Nonuniform search probabilities: exponential distribution Suppose there are N keys in the list: k 1 , . .., k N Suppose the probability that the user will search for key k i is 1/2 i , except for k N which has probability 1/2 N-1 Now if the list is arranged so that key k 1 is in the first list element, k 2 is in the second list element, etc., the average number of comparisons in a successful search is So, with under this rather extreme probabilistic assumption, optimal ordering of the list permits successful search to take constant time in the average case (still O(N) worst- case, though) i 2 i ---- i 1 = N N 2 N ------ + O 1 () =
Background image of page 5

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

View Full Document Right Arrow Icon
Page 6 of 36 CSE 100, UCSD: LEC 19 Nonuniform search probabilities: Zipf distribution Suppose there are N keys in the list: k 1 , . .., k N Suppose the probability that the user will search for key k i is proportional to 1/( i H ( i ) ) , where H () is the harmonic series This probability distribution over keys is known as a Zipf distribution; it fits the observed frequencies of words in natural languages If as before the list is ordered so that key k 1 is in the first list element, k 2 is in the second list element, etc., the average number of comparisons in a successful search is
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 36

lec19 - Lecture 19 Self-organizing data structures lists...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online