Presentation is loading. Please wait.

Presentation is loading. Please wait.

Find Find 13: 15 20 92 616 2318 7 13 11. Find Min and Find Max Find Min: 15 20 92 616 2318 7 13 11 Find Max:

Similar presentations


Presentation on theme: "Find Find 13: 15 20 92 616 2318 7 13 11. Find Min and Find Max Find Min: 15 20 92 616 2318 7 13 11 Find Max:"— Presentation transcript:

1 Find Find 13: 15 20 92 616 2318 7 13 11

2 Find Min and Find Max Find Min: 15 20 92 616 2318 7 13 11 Find Max:

3 Insert Insert 13: 12 17 19 1592 185

4 Insert Insert 13: 12 17 19 1592 185 13

5 Delete Delete 13: 15 20 122 165 2318 7 6 10 13

6 Delete Delete 13: 15 20 122 165 2318 7 6 10 No child (leaf) Deleted directly

7 Delete Delete 16: 15 20 122 516 2318 7 6 10 13

8 Delete Delete 16: 15 20 122 516 2318 7 6 10 13 1 child Splice out node

9 Delete Delete 16: 15 20 122 5 2318 7 6 10 13 tree re-drawn for proper level layout

10 Delete Delete 5: 15 20 122 516 2318 7 6 10 13

11 Delete Delete 5: 15 20 122 516 2318 7 6 10 13 2 children Splice out min node of right sub-tree

12 Delete Delete 5: 15 20 122 516 2318 76 10 13 Orphaned node’s key needs to replace key in node to be deleted

13 Delete Delete 5: 15 20 122 616 2318 7 10 13

14 The Effect of the Input Sequence on the Shape of BSTs The order in which keys arrive and are inserted impacts the shape of the resulting tree The shape of the tree determines performance All input sequences need to be accommodated in a well behaving BST data structure Deletions also affect tree shape (performance)

15 Unbalanced BST Insert the numbers 1, 2, 3, 4, 5, 6, 7 into empty BST: 2 2 Input sequence degenerated the tree into a linked list (linear) data structure. 1 7 6 5 4 3

16 Unbalanced BST Insert the numbers 7, 6, 5, 4, 3, 2, 1 into empty BST: 2 Tree is linear again. 1 7 6 5 4 3

17 Unbalanced BST Insert the numbers 4, 3, 5, 2, 6, 1, 7 into empty BST: 2 Tree is still very unbalanced (near-linear). 1 7 6 5 4 3

18 Unbalanced BST Insert the numbers 1, 3, 2, 5, 4, 7, 6, 8 into empty BST: 4 Tree is still very unbalanced (height is linear). 6 7 5 3 1 2 8

19 Balanced BST Insert the numbers 4, 2, 6, 1, 3, 5, 7 into empty BST: Tree is “dense” with a low height. 1 3 5 7 6 4 2


Download ppt "Find Find 13: 15 20 92 616 2318 7 13 11. Find Min and Find Max Find Min: 15 20 92 616 2318 7 13 11 Find Max:"

Similar presentations


Ads by Google