0
0
DSA C++programming~5 mins

Validate if Tree is BST in DSA C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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 the left child is less and right child is greater to validate a BST?
Because the BST property applies to all descendants, not just immediate children. A node deep in the left subtree must be less than the root, not just its parent.
Click to reveal answer
intermediate
What is a common approach to validate a BST using recursion?
Use a helper function that passes down the allowed minimum and maximum values for each node. Check if the node's value lies within these limits, then recursively check left and right subtrees with updated limits.
Click to reveal answer
beginner
What is the time complexity of validating a BST using the min/max recursion 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?
ALeft subtree nodes < node < Right subtree nodes
BLeft subtree nodes > node > Right subtree nodes
CLeft child < node and Right child > node only
DAll nodes have two children
What is the best way to validate a BST?
ACheck only immediate children values
BUse inorder traversal and check if sorted
CCheck if root is greater than left child
DCount nodes in the tree
What does the min/max recursion method do when validating a BST?
ASwaps nodes to fix the tree
BCounts nodes in left and right subtree
CChecks only leaf nodes
DPasses allowed value range down the tree
What is the time complexity of validating a BST using inorder traversal?
AO(n)
BO(log n)
CO(n log n)
DO(n^2)
If a node violates the BST property, what should the validation function return?
ATrue
BNull
CFalse
DThe node value
Explain how to validate if a binary tree is a BST using recursion with min and max limits.
Think about how allowed value ranges change as you go down the tree.
You got /5 concepts.
    Describe why checking only immediate children is not enough to validate a BST.
    Consider a node far down the left subtree with a value greater than root.
    You got /4 concepts.