Download presentation
Presentation is loading. Please wait.
Published byLester Skinner Modified over 6 years ago
1
d-heaps Same as binary heaps, except d children instead of 2.
array implementation insert: O(logd N) delete: O(d logd N) Why d-heaps? 10 16 12 80 45 27 78 23 95 15 90 95 87 54 59 Nov 7, 2001 CSE 373, Autumn 2001
2
Quadtrees Application: image representation (graphics)
Idea: recursively represent the image into finer and finer detail. Nov 7, 2001 CSE 373, Autumn 2001
3
Octrees Similar idea for 3-D images.
Hidden surface removal: Draw cells that are “farther back” first. Nov 7, 2001 CSE 373, Autumn 2001
4
Other applications Hash tables: B-trees:
compilers: keeping track of symbols finding out what is known about a genetic sequence passwords: hash functions B-trees: drivers license database telephone directory Nov 7, 2001 CSE 373, Autumn 2001
5
Optimal BSTs Suppose each key has a different frequency of access.
unsorted list: keep the most frequently accessed items at the front of the list. By analogy, in a BST, more frequently accessed keys ought to be kept closer to the root. A: 0.35, B: 0.3, C: 0.35 A A B C C B C A C A B C B B A Nov 7, 2001 CSE 373, Autumn 2001
6
Finding the Optimal Tree
Brute force: (4n / n3/2) trees. Let K1 < K2 < … < Kn be the keys in their dictionary order, and let pi be the probability of accessing Ki. Let T be any tree constructed from the keys Kj, …, Kk, where 1 j k n. T is optimal if its cost is as small as the cost of any other tree with the same keys. Nov 7, 2001 CSE 373, Autumn 2001
7
Observation: Every subtree of an optimal tree is itself optimal.
Suppose d 0, if we know the optimal trees for Ki, …, Ki+c for c < d and 1 i n-d, then we can compute the optimal tree for the keys Kj, …, Kj+d for all j n-d. T TR TL Nov 7, 2001 CSE 373, Autumn 2001
8
How? For all possible roots, find the left and right subtrees that are optimal. Choose the root that results in the tree with the lowest cost. Recursion? No! n C 1 1 (n3) running time n C[j,k] – cost of the optimal tree on keys j through k r[j,k] – root of the optimal tree Nov 7, 2001 CSE 373, Autumn 2001
9
Probability-balanced trees
Choose the root Kl so that p(1, l-1) p(l+1, n) Can build the tree in linear time. Can prove that the expected search time is within a factor of 2 of optimal. In practice: within a few percent of optimal. Nov 7, 2001 CSE 373, Autumn 2001
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.