0
0
DSA Typescriptprogramming~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does BST stand for and what is its key property?
BST stands for Binary Search Tree. Its key property is that for every node, all nodes in the left subtree have smaller values, and all nodes in the right subtree have larger values.
Click to reveal answer
beginner
What is the main idea behind validating if a binary tree is a BST?
The main idea is to check if every node's value lies within a valid range defined by its ancestors, ensuring left children are smaller and right children are larger.
Click to reveal answer
intermediate
In TypeScript, what type of traversal is commonly used to validate a BST?
In-order traversal is commonly used because it visits nodes in ascending order if the tree is a BST.
Click to reveal answer
intermediate
Why can't we just check if left child < node < right child to validate BST?
Because this only checks immediate children, not the entire subtree. A node deeper in the left subtree might violate the BST property if it is greater than the root.
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 traversal order helps verify if a binary tree is a BST by checking ascending order?
APost-order traversal
BPre-order traversal
CLevel-order traversal
DIn-order traversal
What must be true for every node in a BST regarding its left subtree?
AAll nodes in left subtree are smaller
BAll nodes in left subtree are larger
CLeft subtree can have any values
DLeft subtree must be empty
Why is checking only immediate children insufficient to validate a BST?
ABecause only root matters
BBecause deeper nodes might violate BST property
CBecause BST allows duplicates anywhere
DBecause children can have equal values
What is the best way to keep track of valid value ranges when validating BST?
ACheck only node values without range
BUse a queue to store nodes
CPass min and max allowed values down the recursion
DCompare node with root only
What is the time complexity of validating a BST by visiting each node once?
AO(n)
BO(log n)
CO(n^2)
DO(1)
Explain how to validate if a binary tree is a BST using recursion and value ranges.
Think about how ancestors restrict node values.
You got /4 concepts.
    Describe why in-order traversal output should be sorted for a BST and how this helps validation.
    Consider the order nodes are visited in a BST.
    You got /4 concepts.