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

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

1 Binary Search Trees (BSTs)

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

View Full Document
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.
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.

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

View Full Document
4 BST: Example. 91 65 73 53 14 35 93 50 33 0 40 44 56 55 58 81 80 71 87 69
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.

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern