Recall & Review
beginner
What is a Binary Search Tree (BST)?
A Binary Search Tree is a tree where each node has at most two children. For every node, all nodes in its left subtree have smaller values, and all nodes in its right subtree have larger values.
Click to reveal answer
beginner
What is the main property to check when validating if a tree is a BST?
We must ensure that for every node, all values in the left subtree are less than the node's value, and all values in the right subtree are greater than the node's value.
Click to reveal answer
intermediate
Why can't we just check if left child < node < right child to validate BST?
Because the BST property applies to the entire left and right subtrees, not just immediate children. A violation can happen deeper in the subtree.
Click to reveal answer
intermediate
What approach can we use to validate a BST efficiently?
Use recursion with a range of allowed values for each node. Initially, the range is infinite. For left child, update the upper bound; for right child, update the lower bound.
Click to reveal answer
beginner
What is the time complexity of validating a BST using the range method?
The time complexity is O(n), where n is the number of nodes, because each node is visited once.
Click to reveal answer
Which condition must hold true for every node in a BST?
✗ Incorrect
The BST property requires all nodes in the left subtree to be less than the node, and all nodes in the right subtree to be greater.
What is the best way to validate a BST?
✗ Incorrect
Using recursion with min and max limits ensures all nodes satisfy BST properties throughout the tree.
What is the time complexity of validating a BST with n nodes?
✗ Incorrect
Each node is visited once, so the time complexity is O(n).
If a node violates the BST property, what should the validation function do?
✗ Incorrect
The function should return false immediately when a violation is found.
Which traversal can help check if a tree is a BST by producing a sorted sequence?
✗ Incorrect
Inorder traversal of a BST produces nodes in ascending order.
Explain how to validate if a binary tree is a BST using recursion and value ranges.
Think about limiting the allowed values for each subtree.
You got /5 concepts.
Describe why checking only immediate children is not enough to validate a BST.
Consider a node deep in the left subtree that violates the BST property.
You got /4 concepts.