Q. Program to find the largest element in a Binary Tree.ExplanationIn this program, we will find out the largest node in the given binary tree. We first define variable max that will hold root's data. Then, we traverse through the left subtree to find the largest node. Compare it with max and store the maximum of two in a variable max. Then, we traverse through the right subtree to find the largest node and compare it with max. In the end, max will have the largest node. Above diagram represents a binary tree. Initially, max will hold 15. Recursive through left subtree. Recursive through right subtree. Recurse in the left subtree of 35 Recurse in the right subtree of 35 So, the largest node in above binary tree is 74. Algorithm
SolutionPythonOutput: Largest element in the binary tree: 74 COutput: Largest element in the binary tree: 74 JAVAOutput: Largest element in the binary tree: 74 C#Output: Largest element in the binary tree: 74 PHPOutput: Largest element in the binary tree: 74
Next TopicPrograms List
