Question
Given the following code snippet, which operation is
performed on the binary tree to produce the output: 4, 2, 5, 1, 3 ? class Node { int data; Node left, right; Node( int value) { data = value; left = right = null ; } } void traverse (Node root) { if (root == null ) return ; traverse(root.left); System.out.print(root.data + " " ); traverse(root.right); }Solution
The given code performs Inorder Traversal on a binary tree. In this traversal method, the left subtree is visited first, followed by the root node, and finally the right subtree. The recursive calls in the code explicitly follow this order:
- traverse(root.left) visits the left subtree.
- System.out.print(root.data) processes the root node.
- traverse(root.right) visits the right subtree.
Which of the following pairs the second person sits to the immediate right of the first person?
Which of the following pair sits in the extreme end?
How many seats are there around the table?
The position of how many people will remain unchanged if they are seated alphabetically in clockwise direction starting from E?
Who among the following stands third to the right of H?
Six persons Om, Yash, Rohit, Prateek, Tanu and Umesh are sitting in a straight horizontal row facing towards the south. Umesh sits second to the right ...
Which of the statement is true?
Six friends Chinu, Minu, Prem, Pari, Vansh and Vishu are sitting in a circle and facing the centre. Prem is to the immediate left of Pari. Only Vansh is...
Six people, T, U, V, W, X and Y are sitting around a circular table facing towards the centre (but not necessarily in the same manner). One person is si...
Four of the five among the following are similar in such a way to forms a group, who among the following doesn’t belong to that group?