Presentation is loading. Please wait.

Presentation is loading. Please wait.

Splay trees Go&Ta 10.3. How do you organize your world?

Similar presentations


Presentation on theme: "Splay trees Go&Ta 10.3. How do you organize your world?"— Presentation transcript:

1 Splay trees Go&Ta 10.3

2 How do you organize your world?

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31 “move to front” heuristic …

32 splay trees A method that modifies a binary search tree (bst) Something like a rotation in AVL There are 3 operations: zig-zig, zig-zag, and zig

33 splay treeszig-zig T2 T3T4 T1 z y x x and y are right children (or left children, symmetry)

34 splay treeszig-zig T2 T3T4 T1 z y x T2 T3 T4 T1 z y x zig-zig

35 splay treeszig-zag T4 T2T3 T1 z y x one of x and y is a left children and the other is a right child (also symmetry)

36 splay treeszig-zag T4 T2T3 T1 z y x T4 T2T3 T1 zy x zig-zag

37 splay treeszig T2 T3T4 T1 y x w x has no grandparent (also symmetry)

38 splay treeszig T2 T3T4 T1 y x w zig T4 T2T3 T1 yw x

39 splay trees We repeat these splay steps until x becomes the root When do we splay? we insert k into the bstree x is the new node with key k we search for k in the bstree x is node with key k or node where we stopped search we delete k from the bstree delete method ultimately removes a leaf the leaf is x

40 splay trees Advantages: frequently accessed data moves nearer to root the “move to front” heuristic average performance is O(log(n)) simple no additional information/data required add-on to bstree

41 splay trees Disdvantages: worst case height can be linear O(n)

42 splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?

43 splay treesrefresher Nodes in a Complete Binary Tree

44 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1

45 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree

46 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: 0 + 1 + 1 + 2 + 2 + 2 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + …

47 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: 0 + 1 + 1 + 2 + 2 + 2 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + …

48 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree

49 splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes 0 1 1 2^1 - 1 1 2 3 2^2 – 1 2 4 7 2^3 – 1 3 8 15 2^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree Average path length is then O(log(n))

50 splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?

51 splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth? Answer: average depth would be more meaningful

52 splay trees Show me a demo


Download ppt "Splay trees Go&Ta 10.3. How do you organize your world?"

Similar presentations


Ads by Google