Prev: W3, Next: W5

Zoom: Link, TopHat: Link (936525), GoogleForm: Link, Piazza: Link, Feedback: Link, GitHub: Link, Sec1&2: Link


Slide:

# Slides and Notes

📗 From sections 1 and 2:
➩ Recursion notes: Link.
➩ Trees note: Link.
➩ Search tree notes: Link.
➩ Trees slides: Link.

# Binary Search Tree (BST)

📗 Every node has 0 or 1 parent and 0, 1, or 2 children.
📗 The height of a tree is the number of nodes from the root to the tree's deepest leaf.
➩ Visualization: .

# BST Small Example

ID:
📗 [1 point] Search for the value of the item associated with in the following BST.

📗 Click on the current node to list the item: .

# BST Large Example

ID:
📗 [1 point] Search for the value of the item associated with in the following BST.

📗 Click on the current node to list the item: .



# Tree Traversals

📗 Values in a tree can be converted into a list by:
➩ In-order.
➩ Pre-order.
➩ Post-order.
➩ Level-order.



# BST Operations

📗 Number of nodes in a BST: \(N\), height of a BST: \(H\).
📗 Search a value: \(O\left(H\right)\)
📗 Inserting value into tree: \(O\left(H\right)\)
📗 Deleting value from tree (leaf nodes): \(O\left(H\right)\)
📗 Deleting value from tree (one child): \(O\left(H\right)\)
📗 Deleting value from tree (two children): \(O\left(H\right)\)



# Insertion Sequence

📗 When the height of the BST is \(H\), then the number of nodes is:
➩ Minimum: \(N\).
➩ Maximum: \(2^{H} - 1\).
📗 When the number of nodes is \(N\), the height of a BST is:
➩ Minimum: \(\log_{2}\left(N + 1\right)\) or \(O\left(\log\left(N\right)\right)\).
➩ Maximum: \(N\).

# BST Height Example

ID:
📗 [1 point] What is the minimum and maximum heights of the tree with these nodes. The insertion order is: .

The height of the tree is: .  



# Questions?



📗 Notes and code adapted from the course taught by Professors Gurmail Singh, Yiyin Shen, Tyler Caraza-Harter.
📗 If there is an issue with TopHat during the lectures, please submit your answers on paper (include your Wisc ID and answers) or this Google form Link at the end of the lecture.
📗 Anonymous feedback can be submitted to: Form. Non-anonymous feedback and questions can be posted on Piazza: Link

Prev: W3, Next: W5





Last Updated: February 10, 2026 at 10:03 PM