MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of the following traversal outputs the data in sorted order in a BST?
A
Preorder
B
PostOrder
C
Inorder
D
None of the above
Explanation: 

Detailed explanation-1: -Which of the following traversal outputs the data in sorted order in a BST? Explanation: Inorder traversal of a BST outputs data in sorted order.

Detailed explanation-2: -Inorder traversal It means that first left subtree is visited after that root node is traversed, and finally, the right subtree is traversed. As the root node is traversed between the left and right subtree, it is named inorder traversal. So, in the inorder traversal, each node is visited in between of its subtrees.

Detailed explanation-3: -Yes, it is. Since the elements of the BST satisfy a total preorder, an in-order traversal of the BST must produce those elements in order (Ex: prove it). It is equivalent to state that if we had stored a BST’s keys, by an in-order traversal, in an array, the array would be sorted.

There is 1 question to complete.