Question
Download Solution PDFSuppose a binary search tree has been constructed from the following sequence of numbers in the order in which they arrive : 6, 2, 10, 1, 5, 7, 11, 3, 9, 4, 8. Consider the following piece of code :
Show(root) { if (root !=NULL)
{ printf(“% d”, root → key);
show (root → right);
show (root → left);
}
else
return ;
}
The sequence printed will be :
Answer (Detailed Solution Below)
Detailed Solution
Download Solution PDFThe correct answer is: Option 3
Key Points
- We are given a sequence of numbers to build a Binary Search Tree (BST): 6, 2, 10, 1, 5, 7, 11, 3, 9, 4, 8
- The function
Show(root)
performs a non-standard traversal:- Visit Root
- Traverse Right Subtree
- Traverse Left Subtree
Step-by-step construction of BST:
- Insert 6 → root
- 2 goes to left of 6
- 10 to right of 6
- 1 to left of 2
- 5 to right of 2
- 7 to left of 10
- 11 to right of 10
- 3 to left of 5
- 9 to right of 7
- 4 to right of 3
- 8 to left of 9
Traversal Output (Root → Right → Left):
6, 10, 11, 7, 9, 8, 2, 5, 3, 4, 1
Therefore, the correct option is: Option 3.
Last updated on Jul 3, 2025
-> NIELIT Scientific Assistant answer key 2025 has been released at the official website.
-> NIELIT Scientific Assistant admit card 2025 has been released.
-> NIELIT Scientific Assistant city intimation slip 2025 has been released at the official website.
-> NIELIT Scientific Assistant exam 2025 is scheduled to be conducted on June 28.
-> A total number of 113 revised vacancies have been announced for the post of Scientific Assistant in Computer Science (CS), Information Technology (IT), and Electronics & Communication (EC) streams.
-> Online application form, last date has been extended up to from 17th April 2025.
->The NIELT has revised the Essential Qualifications for the post of Scientific Assistant. Candidates must possess (M.Sc.)/ (MS)/ (MCA) / (B.E.)/ (B.Tech) in relevant disciplines.
-> The NIELIT Scientific Assistant 2025 Notification has been released by the National Institute of Electronics and Information Technology (NIELIT).