Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Which of the following traversal outputs the ... Start Learning for Free
Which of the following traversal outputs the data in sorted order in a BST?
  • a)
    Preorder
  • b)
    Inorder
  • c)
    Postorder
  • d)
    Level order
Correct answer is option 'B'. Can you explain this answer?
Most Upvoted Answer
Which of the following traversal outputs the data in sorted order in a...
Explanation:

In a Binary Search Tree (BST), each node has a key greater than all the keys in its left subtree and smaller than all the keys in its right subtree. Therefore, inorder traversal of a BST visits the nodes in ascending order of their keys.

Inorder Traversal:

Inorder traversal follows the order of Left-Root-Right. It starts from the left subtree, visits the root node, and then the right subtree. This traversal is used to get the elements in sorted order for BST.

Example:

Consider the following BST:

50
/ \
30 70
/ \ / \
20 40 60 80

Inorder traversal of the given tree will output the data in sorted order.

Inorder Traversal: 20 30 40 50 60 70 80

Other Traversals:

Preorder, Postorder, and Level order traversals don't follow the order of keys in a BST.

- Preorder traversal follows the order of Root-Left-Right.
- Postorder traversal follows the order of Left-Right-Root.
- Level order traversal visits the nodes level by level from left to right.

Therefore, inorder traversal is the only traversal that outputs data in sorted order for a BST.
Free Test
Community Answer
Which of the following traversal outputs the data in sorted order in a...
Inorder traversal of a BST outputs data in sorted order. Read here for details.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer?
Question Description
Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer?.
Solutions for Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer?, a detailed solution for Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? has been provided alongside types of Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Which of the following traversal outputs the data in sorted order in a BST?a)Preorderb)Inorderc)Postorderd)Level orderCorrect answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev