Lect6 - Binary Search Trees(BSTs 1 Binary Search Trees(BSTs...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Binary Search Trees (BSTs)
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Binary Search Trees (BSTs) Consider the search operation FindKey (): find an element of a particular key value in a binary tree. This operation takes O(n) time in a binary tree. In a binary tree of 10 6 nodes 10 6 steps required at least. In a BST this operation can be performed very efficiently: O(log 2 n). A binary search tree of 10 6 nodes log 2 (10 6 ) 2245 20 steps only are required.
Image of page 2
3 Binary Search Trees (BSTs) A binary search tree is a binary tree such that for each node, say N, the following statements are true: 1. If L is any node in the left subtree of N, then L is less than N. 2. If R is any node in the right subtree of N, then R is greater than N.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 BST: Example. 91 65 73 53 14 35 93 50 33 0 40 44 56 55 58 81 80 71 87 69
Image of page 4
5 BST: Searching The search operation in a binary search tree can be carried out as: While (the target element is not found and there is more tree to search) do if the target element is “less than” the current element then search the left subtree else search the right subtree.
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 ADT Binary Search Tree Elements: The elements are nodes (BSTNode), each node contains the following data type: Type Structure: hierarchical structure; each node can have two children: left or right child; there is a root node and a current node. If N is any node in
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern