1 / 20

Analysis of Algorithms Chapter - 05 Binary Search Tree

Analysis of Algorithms Chapter - 05 Binary Search Tree. Binary Search Trees (Chapter 13[12]). Preorder, Inorder, Postorder Walks (Chapter 13[12].1). Querying a Binary Search Tree (Section 13[12].2). Min, Max, Successor in a Binary Search Tree (Section 13[12].2).

mho
Download Presentation

Analysis of Algorithms Chapter - 05 Binary Search Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 yz • else yTree-Successor(z) • If left[y]nil[T] • then xleft[y] • else xright[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

  12. Trees - Searching

  13. Trees - Searching

  14. Trees - Searching

  15. Trees - Searching

  16. Trees - Searching

  17. Left-, Right-Rotate: Implementation

More Related