0
0
DSA Typescriptprogramming~5 mins

BST Search Operation in DSA Typescript - 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 data structure 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
How does the search operation work in a BST?
Start at the root. If the value equals the node's value, return it. If smaller, search the left subtree. If larger, search the right subtree. Repeat until found or reach a null node.
Click to reveal answer
intermediate
What is the time complexity of searching in a BST?
The average time complexity is O(log n) when the tree is balanced. In the worst case (skewed tree), it can be O(n).
Click to reveal answer
beginner
What happens if the search value is not in the BST?
The search will continue down the tree until it reaches a null node, meaning the value is not present. The operation returns null or indicates not found.
Click to reveal answer
intermediate
Show the TypeScript code snippet for searching a value in a BST node.
function searchBST(root: TreeNode | null, val: number): TreeNode | null {
  if (root === null || root.val === val) {
    return root;
  }
  if (val < root.val) {
    return searchBST(root.left, val);
  } else {
    return searchBST(root.right, val);
  }
}
Click to reveal answer
In a BST, if the search value is less than the current node's value, where do you search next?
ARoot node
BRight subtree
CSibling node
DLeft subtree
What is the worst case time complexity of searching in a balanced BST?
AO(n)
BO(1)
CO(log n)
DO(n log n)
If the search value equals the current node's value, what should the search operation do?
AReturn the current node
BSearch left subtree
CSearch right subtree
DReturn null
What does the search operation return if the value is not found in the BST?
AThe root node
BNull or not found
CThe smallest node
DThe last visited node
Which traversal method is used in the BST search operation?
ADirected search based on value comparison
BPreorder traversal
CPostorder traversal
DInorder traversal
Explain how the search operation works in a Binary Search Tree.
Think about how you decide which way to go at each node.
You got /6 concepts.
    Describe the time complexity of searching in a BST and what affects it.
    Consider how the shape of the tree changes search speed.
    You got /4 concepts.