What is the in-order traversal of a binary search tree (BST)?
a) Left, Root, Right
b) Root, Left, Right
c) Right, Left, Root
d) Left, Right, Root
Answer:
a) Left, Root, Right
Explanation:
In-order traversal of a binary search tree (BST) visits nodes in the following order: left subtree, root, and then right subtree. This traversal results in visiting the nodes in ascending order of their values, making it particularly useful for BSTs.
In-order traversal can be implemented recursively or iteratively using a stack. It is commonly used to retrieve all the elements of a BST in sorted order.
Other types of tree traversal include pre-order (Root, Left, Right) and post-order (Left, Right, Root), each serving different purposes in tree operations.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers