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.
From when will RBI’s bar on prepayment penalties for floating rate loans to MSEs be effective?
Bhadra Tiger Reserve, recently seen in news, is located in which state?
What is the primary focus of AgriHub, the AI-driven Center of Excellence launched by MeitY and IIT Indore?
What is the main purpose of the AgriSURE Fund launched by the Union Agriculture Minister?
What is the renewable energy capacity target that India aims to achieve by 2030?
What is India’s projected GDP growth for FY26 according to ICRA?
NITI Aayog’s report “Pathways to Progress” focuses on which area?
The government of India slashed the windfall tax on domestically produced petroleum crude to what value effective from September 18, 2024?
What unique feature does the HSBC Taj Credit Card emphasize?
What is the primary aim of APEDA’s ‘Indian Mango Mania 2025’ campaign held in Abu Dhabi?