What is the inorder successor of a node in a Binary Search Tree (BST)?
The inorder successor of a node in a BST is the node with the smallest key greater than the given node's key. It is the next node visited in an inorder traversal.
Click to reveal answer
beginner
How do you find the inorder successor if the node has a right child?
If the node has a right child, the inorder successor is the leftmost node in the right subtree.
Click to reveal answer
intermediate
How do you find the inorder successor if the node has no right child?
If the node has no right child, the inorder successor is one of its ancestors. Specifically, it is the lowest ancestor whose left child is also an ancestor of the node.
Click to reveal answer
intermediate
What is the time complexity of finding the inorder successor in a BST?
The time complexity is O(h), where h is the height of the BST, because you may need to traverse up or down the tree along the height.
Click to reveal answer
beginner
In C, what data structure is commonly used to represent a BST node for inorder successor operations?
A struct with an integer key and pointers to left and right child nodes is commonly used to represent a BST node.
Click to reveal answer
What is the inorder successor of the maximum node in a BST?
AThe root node
BThe minimum node
CNULL (no successor)
DThe parent node
✗ Incorrect
The maximum node has no inorder successor because there is no node with a greater key.
If a node has a right child, where do you look to find its inorder successor?
ARight child's leftmost node
BRight child's rightmost node
CLeft child's leftmost node
DParent node
✗ Incorrect
The inorder successor is the leftmost node in the right subtree.
If a node has no right child, how do you find its inorder successor?
AGo to the left child
BGo to the right child
CNo successor exists
DGo up to the lowest ancestor whose left child is also ancestor of the node
✗ Incorrect
You move up the tree to find the lowest ancestor where the node is in the left subtree.
What is the worst-case time complexity to find the inorder successor in a BST?
AO(log n)
BO(h)
CO(n)
DO(1)
✗ Incorrect
The time depends on the height h of the BST, which can be up to O(n) in worst case.
Which of these is NOT part of a typical BST node struct in C?
APointer to parent
BPointer to right child
CPointer to left child
DInteger key
✗ Incorrect
Parent pointer is optional and not always included in BST node structs.
Explain how to find the inorder successor of a node in a BST when it has a right child and when it does not.
Think about moving down the right subtree or moving up to ancestors.
You got /2 concepts.
Describe the time complexity of finding the inorder successor in a BST and why it depends on the tree's height.
Consider the longest path you might travel in the tree.
You got /3 concepts.
Practice
(1/5)
1. What is the inorder successor of a node in a Binary Search Tree (BST)?
easy
A. The node with the largest key smaller than the given node's key
B. The node with the smallest key greater than the given node's key
C. The left child of the given node
D. The right child of the given node
Solution
Step 1: Understand inorder traversal in BST
Inorder traversal visits nodes in ascending order of their keys.
Step 2: Define inorder successor
The inorder successor of a node is the next node visited after it in inorder traversal, which is the smallest node greater than it.
Final Answer:
The node with the smallest key greater than the given node's key -> Option B
Quick Check:
Inorder successor = next bigger node [OK]
Hint: Inorder successor is next bigger node in sorted order [OK]
Common Mistakes:
Confusing successor with predecessor
Thinking successor is always right child
Assuming successor is left child
2. Which of the following C function signatures correctly represents a function to find the inorder successor of a BST node?
easy
A. struct Node* inorderSuccessor(struct Node* root, struct Node* n);
B. int inorderSuccessor(int root, int n);
C. void inorderSuccessor(struct Node* root);
D. struct Node inorderSuccessor(struct Node n);
Solution
Step 1: Analyze function parameters
The function needs the BST root and the node to find successor for, both as pointers.
Step 2: Analyze return type
It should return a pointer to the successor node, so return type is struct Node*.
A. It incorrectly updates successor when moving right
B. It returns the wrong node when node has right child
C. It uses a while loop instead of recursion
D. It does not handle the case when node has no right child
Solution
Step 1: Check handling of right child
Code correctly finds leftmost node in right subtree if right child exists.
Step 2: Check updating successor when moving right
In the else branch (n->data >= root->data), it incorrectly sets succ = root before moving right. Successor should NOT be updated when going right, as n is in (or at) the right subtree.
Step 3: Identify error
The main logical error is incorrectly updating the successor when traversing right.
Final Answer:
It incorrectly updates successor when moving right -> Option A
Quick Check:
Successor updates only on left moves [OK]
Hint: Successor updates only when moving left in BST [OK]
Common Mistakes:
Thinking recursion is required
Updating successor when moving right
Ignoring right subtree case
5. You have a BST and want to find the inorder successor of the node with value 25. The BST is:
20
/ \
10 30
/ \ / \
5 15 25 40
If the node with value 25 has no right child, what is the inorder successor and why?
hard
A. 20, because it is the root
B. 40, because it is the right child of 30
C. No successor, because 25 has no right child
D. 30, because it is the lowest ancestor greater than 25
Solution
Step 1: Check if node 25 has right child
Node 25 has no right child, so successor is an ancestor.
Step 2: Find lowest ancestor greater than 25
Ancestor 30 is greater than 25 and is the lowest such ancestor.
Final Answer:
30, because it is the lowest ancestor greater than 25 -> Option D
Quick Check:
Successor = nearest bigger ancestor [OK]
Hint: If no right child, successor is nearest bigger ancestor [OK]
Common Mistakes:
Choosing right child 40 incorrectly
Saying no successor exists
Choosing root 20 incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.