Questions
3 of 26
1What is a Tree? Define Node, Root, Leaf, Edge, Height, Depth.
2What is a Binary Tree?
3What is a Binary Search Tree (BST)? What are its properties?
4What is the difference between a Binary Tree and a Binary Search Tree?
5Explain Tree Traversals: Inorder, Preorder, Postorder, Level Order.
6How do you implement Inorder traversal iteratively? (Without recursion)
7How do you find the Lowest Common Ancestor (LCA) of two nodes in a BST?
8How do you validate if a given Tree is a valid BST?
9What is a Balanced Tree? Why do we need balance?
10What is a Complete Binary Tree? A Full Binary Tree? A Perfect Binary Tree?
11What is a Heap? (Min-Heap and Max-Heap)
12How is a Heap implemented using an Array? (Parent/Child index math)
13What is the time complexity of insertion and deletion in a Heap? Why?
14What is Heapify? Explain the process.
15What is a Trie (Prefix Tree)? When is it used?
16How does a Trie compare to a Hash Table for string storage?
17What is an AVL Tree? What is a Red-Black Tree? What is the difference?
18Why do databases prefer B-Trees/B+ Trees over Binary Search Trees?
19How do you serialize and deserialize a Binary Tree?
20What is a Segment Tree? What problems does it solve?
21What is a Fenwick Tree (Binary Indexed Tree)?
22What is the difference between a B-Tree and a B+ Tree? Why are B+ Trees better for disk access?
23Explain the concept of Tree Rotation.
24What is a Splay Tree? When would you use it?
25How do you find the diameter of a Binary Tree?
26How do you check if a tree is symmetric (Mirror image)?
03 / 26

What is a Binary Search Tree (BST)? What are its properties?

Difficulty: 5/10
insertion, deletion, balancing

Binary Search Tree

A Binary Search Tree is a binary tree that maintains an ordering invariant. For a node, values in the left subtree are smaller and values in the right subtree are larger, assuming the implementation does not allow duplicates. This ordering enables efficient search, insertion, and deletion when the tree remains balanced.

javascript
  1. 1

    Left subtree contains smaller values.

  2. 2

    Right subtree contains larger values.

  3. 3

    Inorder traversal produces sorted order.

  4. 4

    Search, insertion, and deletion are O(h), where h is tree height.

  5. 5

    For a balanced BST, these operations are typically O(log n).

  6. 6

    For a highly skewed BST, they can degrade to O(n).

Scenario Questions

0-2 years experience

  1. 1We need to store usernames and support fast lookup by name. How would you use a BST for this, and what happens if the usernames arrive already sorted?
  2. 2If you insert the sequence 5, 3, 7, 2, 4 into an empty BST, can you walk me through the shape of the tree after each insertion?
  3. 3Given a BST, how would you find the smallest value that is greater than a target key?

2-5 years experience

  1. 1Our feature uses a BST to keep a sorted set of timestamps for event ordering, but we sometimes see O(n) search times. What could cause that and how would you debug it?
  2. 2We replaced a hash map with a BST to get ordered iteration. What trade‑offs are you considering, and how would you decide if the change is worthwhile?
  3. 3During a code review you notice the delete operation is leaving the tree unbalanced after many deletions. How would you fix the issue without rewriting the whole structure?

5-8 years experience

  1. 1Our service stores millions of user sessions in an in‑memory BST for range queries. Discuss scalability concerns and alternative data structures you might choose.
  2. 2We need to persist a BST to disk and reload it quickly after a restart. What design would you use to keep the tree balanced and minimize load time?
  3. 3When implementing a concurrent BST for a high‑throughput API, what synchronization strategies could you employ, and what are their performance implications?

8+ years experience

  1. 1Our legacy system uses a custom BST for document indexing, but the codebase is hard to maintain and doesn't handle modern workloads. How would you plan a migration to a more robust solution while minimizing downtime?
  2. 2Multiple services have duplicated BST logic for different domain objects. What architectural changes would you propose to unify this functionality and ensure consistency?
  3. 3If you were to design a library that provides generic, self‑balancing BSTs for several languages in our ecosystem, what API design, testing, and versioning considerations would you prioritize?

Follow-up Questions

  • How does the tree's height affect lookup time?
  • What would change if you used a self‑balancing variant?
  • How would you verify correctness after a series of operations?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.