Download presentation
Presentation is loading. Please wait.
1
Analysis of Algorithms
Chapter - 05 Binary Search Tree
2
Binary Search Trees (Chapter 13[12])
3
Preorder, Inorder, Postorder Walks
(Chapter 13[12].1)
4
Querying a Binary Search Tree
(Section 13[12].2)
5
Min, Max, Successor in a Binary Search Tree
(Section 13[12].2)
6
Insertion in a Binary Search Tree
(Section 13[12].3) Insert`Note: Tree-Insert begins at the root of the tree and traces a path downward. The pointer x traces the path, and the pointer y is maintained as the parent of x. after initialization, the while loop in line 3-7 causes these two pointer to move down the tree, going left or right depending on the comparison of key[z] with key[x], until x is set to NIL. This NIL occupies the position where we wish to place the input item z. lines 8-13 set the pointers that cause z to be inserted. It runs in O(h) time on a tree of height h.
7
Deletion in a Binary Search Tree
(Section 13[12].3) Deleting a node z from a binary search tree. In each case, the node actually removed is lightly shaded. (a) If z has no children, we just remove it.
8
Deletion in a Binary Search Tree
(Section 13[12].3) Deleting a node z from a binary search tree. In each case, the node actually removed is lightly shaded. (b) If z has only one child, we splice out z.
9
Deletion in a Binary Search Tree
(Section 13[12].3) Deleting a node z from a binary search tree. In each case, the node actually removed is lightly shaded. (c) If z has two children, we splice out its successor y, which has at most one child, and then replace the contents of z with the contents of y.
10
Tree-Delete(T,z) If left[z] =nil[T] or right[z]=nil[T] then yz else yTree-Successor(z) If left[y]nil[T] then xleft[y] else xright[y] P[x]p[y] If p[y]=nil[T] then root[T]x else if y=left[p[y]] then left[p[y]]x else right[p[y]] x If y z then key[z] key[y] {{if y has other fields, copy them, too. Return y
11
Tree Traversal
15
Trees - Searching
16
Trees - Searching
17
Trees - Searching
18
Trees - Searching
19
Trees - Searching
20
Left-, Right-Rotate: Implementation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.