Find maximum element in binary tree

In this post, we will see how to find maximum element in binary tree.

Maximum element binary tree


Algorithm

Here is simple algorithm to find maximum element in binary tree.

  • If root is null, return Integer.MIN_VALUE
  • Assign currentNode.data to curretValue
  • Traverse left child of root recursively,assign it to variable leftTreeMax
  • Traverse right child of root recursively,assign it to variable rightTreeMax
  • Compare leftTreeMax and rightTreeMax with curretValue and find maximum

<hr\>

Complete java program to count leaf nodes in binary tree

Output

Maximum value in binary tree: 100

Leave a Reply

Your email address will not be published. Required fields are marked *