Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Tree AlgorithmsEasy
Q1. How do you find the minimum element in a BST?
- A.Check the root node
- B.Traverse to the rightmost node
- C.Perform in-order traversal
- D.Traverse to the leftmost node✓ Correct
Explanation
In a BST, the minimum element is at the leftmost node, found by following left child pointers from the root.
Report an error in this question
Tree AlgorithmsEasy
Q2. Which traversal of a BST gives elements in sorted order?
- A.Level-order
- B.In-order✓ Correct
- C.Post-order
- D.Pre-order
Explanation
In-order traversal of a BST visits nodes in ascending sorted order (left, root, right).
Report an error in this question
Tree AlgorithmsEasy
Q3. What data structure is used for level-order (BFS) traversal of a tree?
- A.Array
- B.Queue✓ Correct
- C.Hash table
- D.Stack
Explanation
Level-order traversal uses a queue to process nodes level by level, enqueueing children as each node is visited.
Report an error in this question
Tree AlgorithmsEasy
Q4. What is post-order traversal of a binary tree?
- A.Right, Root, Left
- B.Root, Left, Right
- C.Left, Root, Right
- D.Left, Right, Root✓ Correct
Explanation
Post-order traversal visits the left subtree, then the right subtree, then the root (Left, Right, Root).
Report an error in this question
Tree AlgorithmsEasy
Q5. What is the height of a single-node tree?
- A.1
- B.0✓ Correct
- C.-1
- D.2
Explanation
A tree with a single node (root only) has height 0, as there are no edges from the root to any leaf.
Report an error in this question
Tree AlgorithmsEasy
Q6. How do you find the maximum element in a BST?
- A.Check the root node
- B.Traverse to the leftmost node
- C.Traverse to the rightmost node✓ Correct
- D.Use binary search method
Explanation
In a BST, the maximum element is at the rightmost node, found by following right child pointers from the root.
Report an error in this question
Tree AlgorithmsEasy
Q7. What is a binary tree's depth?
- A.The edge count from root to deepest leaf✓ Correct
- B.The total number of nodes in tree
- C.The number of internal non-leaf nodes
- D.The total number of leaf nodes only
Explanation
The depth (or height) of a binary tree is the number of edges on the longest path from the root to a leaf node.
Report an error in this question
Tree AlgorithmsMedium
Q8. What is an AVL tree?
- A.A tree with at most 3 children per node always
- B.A self-balancing BST with height difference at most 1✓ Correct
- C.A tree data structure used only for searching
- D.A binary tree with no balancing guarantees
Explanation
An AVL tree is a self-balancing BST where for every node, the heights of the left and right subtrees differ by at most 1.
Report an error in this question
Tree AlgorithmsEasy
Q9. What is the time complexity of searching for an element in a BST of height h?
- A.O(1)
- B.O(n^2)
- C.O(h)✓ Correct
- D.O(n)
Explanation
Search in a BST follows a path from root to a node, taking O(h) time where h is the height of the tree.
Report an error in this question
Tree AlgorithmsMedium
Q10. What are the rotation operations in an AVL tree?
- A.Merge and split operations on subtrees
- B.Insert and delete operations on tree nodes
- C.Push and pop operations on internal nodes
- D.Left, right, left-right, and right-left rotations✓ Correct
Explanation
AVL trees use four types of rotations to maintain balance: single left, single right, left-right (double), and right-left (double) rotations.
Report an error in this question
Tree AlgorithmsEasy
Q11. What is in-order traversal of a binary tree?
- A.Right, Root, Left
- B.Left, Right, Root
- C.Left, Root, Right✓ Correct
- D.Root, Left, Right
Explanation
In-order traversal visits the left subtree first, then the root, then the right subtree (Left, Root, Right).
Report an error in this question
Tree AlgorithmsEasy
Q12. What is pre-order traversal of a binary tree?
- A.Right, Left, Root
- B.Root, Left, Right✓ Correct
- C.Left, Right, Root
- D.Left, Root, Right
Explanation
Pre-order traversal visits the root first, then the left subtree, then the right subtree (Root, Left, Right).
Report an error in this question
Tree AlgorithmsHard
Q13. What is a Fenwick tree (Binary Indexed Tree)?
- A.A balanced BST variant with extra pointers
- B.A structure for O(log n) prefix sums and updates✓ Correct
- C.A tree used in networking protocols
- D.A binary tree indexed by key values
Explanation
A Fenwick tree (BIT) provides O(log n) time for both prefix sum queries and point updates, using a compact array-based representation.
Report an error in this question
Tree AlgorithmsMedium
Q14. What properties must a Red-Black tree satisfy?
- A.All internal and external nodes must always be colored red only
- B.Root is black, red nodes have black children, equal black-height on all paths✓ Correct
- C.Height is always kept at exactly log n for any n total nodes
- D.All leaf nodes are always colored red throughout the entire tree
Explanation
Red-Black tree properties: (1) every node is red or black, (2) root is black, (3) leaves (NIL) are black, (4) red nodes have black children, (5) all root-to-leaf paths have the same number of black nodes.
Report an error in this question
Tree AlgorithmsMedium
Q15. How can you check if a binary tree is a valid BST?
- A.Check if each node has at most 2 children
- B.Count the number of nodes in the tree
- C.Verify in-order traversal is strictly increasing✓ Correct
- D.Check if the root is the minimum value node
Explanation
A valid BST produces a strictly increasing sequence during in-order traversal. Alternatively, recursively check that each node's value is within a valid range.
Report an error in this question
Tree AlgorithmsMedium
Q16. What is a segment tree used for?
- A.Storing sorted segments of linked lists
- B.Efficient range queries and point updates on arrays✓ Correct
- C.Segmenting a network into subnetworks
- D.Storing geometric line segments only
Explanation
A segment tree is used for efficient range queries (e.g., sum, minimum, maximum) and updates on an array, both in O(log n) time.
Report an error in this question
Tree AlgorithmsMedium
Q17. When is a left rotation performed in an AVL tree?
- A.When the tree is already perfectly balanced
- B.When the right subtree is too heavy (RR case)✓ Correct
- C.When the left subtree is too heavy overall
- D.After every single insertion operation occurs
Explanation
A left rotation is performed when the right subtree is heavier (right-right imbalance) to restore the AVL balance property.
Report an error in this question
Tree AlgorithmsHard
Q18. What is a treap?
- A.A BST-heap hybrid with keys and random priorities✓ Correct
- B.A tree-shaped trap data structure
- C.A triple-ended queue data structure
- D.A tree with array-like access properties
Explanation
A treap is a randomized BST where each node has a key (BST property) and a random priority (heap property), providing O(log n) expected time for operations.
Report an error in this question
Tree AlgorithmsHard
Q19. What is the time complexity of range query and update in a segment tree?
- A.O(n) for both operations
- B.O(n) query, O(1) update
- C.O(1) query, O(n) update
- D.O(log n) for both operations✓ Correct
Explanation
A segment tree supports both range queries and point updates in O(log n) time.
Report an error in this question
Tree AlgorithmsHard
Q20. What is lazy propagation in a segment tree?
- A.Deferring updates to children until they are queried✓ Correct
- B.Lazily inserting elements one at a time
- C.Skipping unnecessary queries for performance
- D.Delaying the tree construction until needed
Explanation
Lazy propagation defers range updates to child nodes until those nodes are queried, enabling O(log n) range updates instead of O(n).
Report an error in this question
Tree AlgorithmsMedium
Q21. What is the time complexity of insertion in a Red-Black tree?
- A.O(1)
- B.O(n)
- C.O(n log n)
- D.O(log n)✓ Correct
Explanation
Red-Black tree insertion takes O(log n) time because the tree height is O(log n) and rebalancing (recoloring and rotations) takes O(log n) in the worst case.
Report an error in this question
Tree AlgorithmsMedium
Q22. What is the Lowest Common Ancestor (LCA) of two nodes in a tree?
- A.The deepest node that is ancestor of both✓ Correct
- B.The node with the smallest key value
- C.The root node of the entire tree
- D.The immediate parent of both given nodes
Explanation
The LCA of two nodes is the deepest (farthest from root) node that is an ancestor of both nodes.
Report an error in this question
Tree AlgorithmsMedium
Q23. What is Morris traversal?
- A.A traversal technique for graphs only
- B.An in-order traversal using O(1) extra space✓ Correct
- C.A traversal using an explicit stack structure
- D.A breadth-first traversal using a queue
Explanation
Morris traversal performs in-order traversal without a stack or recursion by using threaded binary tree concepts, temporarily modifying pointers and restoring them.
Report an error in this question
Tree AlgorithmsHard
Q24. What is a splay tree?
- A.A B-tree variant used in database indexing
- B.A self-adjusting BST that moves accessed nodes to root✓ Correct
- C.A tree that spreads elements across multiple arrays
- D.A tree that is always perfectly balanced
Explanation
A splay tree is a self-adjusting BST that performs a splay operation (sequence of rotations) to move an accessed node to the root, providing O(log n) amortized time.
Report an error in this question
Tree AlgorithmsMedium
Q25. How do you delete a node with two children in a BST?
- A.Simply remove the node directly from tree
- B.Swap with the root node then remove it
- C.Replace with in-order successor then delete it✓ Correct
- D.Set the node value to null and leave it
Explanation
To delete a node with two children, replace its value with its in-order successor (smallest in right subtree) or predecessor (largest in left subtree), then delete that successor/predecessor.
Report an error in this question
Tree AlgorithmsHard
Q26. What is the Euler tour technique for trees?
- A.Linearizing a tree by recording DFS visit times✓ Correct
- B.A graph coloring technique for tree nodes
- C.Touring all leaf nodes in level order
- D.Finding Euler paths in tree structures
Explanation
The Euler tour technique linearizes a tree into a sequence by recording entry and exit times during DFS, enabling subtree queries to be converted to range queries.
Report an error in this question
Tree AlgorithmsHard
Q27. What is Heavy-Light Decomposition (HLD) of a tree?
- A.Decomposing into chains for efficient path queries✓ Correct
- B.Separating heavy and light weight nodes
- C.Removing heavy edges from the tree structure
- D.Balancing an unbalanced tree by restructuring
Explanation
HLD decomposes a tree into heavy and light chains so that any root-to-leaf path crosses at most O(log n) chains, enabling efficient path queries with segment trees.
Report an error in this question
Tree AlgorithmsHard
Q28. What is a persistent segment tree?
- A.A segment tree preserving all versions via path copying✓ Correct
- B.A segment tree that never changes after construction
- C.A segment tree stored on disk permanently
- D.A compressed segment tree with reduced memory use
Explanation
A persistent segment tree creates a new version for each update by copying only the modified path (O(log n) nodes), preserving all historical versions.
Report an error in this question
Tree AlgorithmsHard
Q29. How does a B+ tree differ from a B-tree?
- A.B+ tree is not a balanced tree structure
- B.B+ tree has more levels than a B-tree
- C.B+ tree stores all data at leaves with linked leaf nodes✓ Correct
- D.B+ tree has fewer keys per node overall
Explanation
In a B+ tree, only leaf nodes store data records (internal nodes store only keys for routing), and leaf nodes are linked together, supporting efficient range queries.
Report an error in this question
Tree AlgorithmsHard
Q30. What is the time complexity of LCA using binary lifting (sparse table)?
- A.O(n^2) per query with no preprocessing needed
- B.O(n) per query with no preprocessing
- C.O(1) per query after O(n^2) preprocessing
- D.O(log n) per query after O(n log n) preprocessing✓ Correct
Explanation
Binary lifting preprocesses ancestor information in O(n log n) and answers each LCA query in O(log n) by jumping up in powers of 2.
Report an error in this question