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