





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of Binary Search Trees (BSTs), including their implementation, operations supported, and comparison with sorted arrays. It covers the time complexity of various operations and discusses the concept of a balanced BST. The document also includes examples and references to resources for further learning.
Typology: Study notes
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















42 32 12 45 41 50 47 46 51 48
Which of the following is/are a binary search tree? 42 32 12 42 12 32 42 12 32 65 30 38
42 32 12 56 45
E. More than one of these
Ref: Tim Roughgarden (Stanford)
Operations supported: Balanced Binary Search Trees vs. Sorted Array
Ref: Tim Roughgarden (Stanford)
Operations supported: Balanced Binary Search Trees vs. Sorted Array
Ref: Tim Roughgarden (Stanford)
Under the hood of the BST: Searching an element in the tree 42 32 12 45 41
Towards describing the running time of the search operation: Height of the tree What is the height of the given tree?
42 32 12 45 41
Relating H (height) and N (#nodes) for a Balanced BST Level 0 Level 1 Level 2 … … How many nodes are on level L in a completely filled binary search tree? A. 2 B. L C. 2*L D. 2 L
Level 0 Level 1 Level 2 … … How many nodes are in a completely filled BST? A.
Level 0 Level 1 Level 2 … … How many nodes are in a completely filled BST? 𝑁 = 2 ு ୀ
𝑁 = 2 ு ே ுୀ
ுା A. (^) N = 2 B. (^) C. D. − 1 L L = 0 H − 1 ∑
Level 0 Level 1 Level 2 … … Representing the sum in closed form: N = 2 L L = 0 H − 1 ∑ =^2 H − 1
Level 0 Level 1 Level 2 … … Finally, what is the height of the tree in terms of N? And since we knew finding a node was O(H), we now know it is:
N = 2 L L = 0 H − 1 ∑ =^2 H − 1 H = ( N + 1 ) / 2 H = log 2 ( N ) H = log 2 ( N + 1 )