menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Diameter o...
source image

Prodevelopertutorial

1M

read

321

img
dot

Image Credit: Prodevelopertutorial

Diameter of a Binary Tree

  • To find the diameter of a binary tree, we need to calculate the longest path between two leaf nodes.
  • The diameter can pass through the root or not. If it does, the formula is (left_height + right_height + 1).
  • If the diameter doesn't pass through the root, we use the formula max(left_diameter, right_diameter).
  • The function for finding the diameter calculates the heights and diameters of the left and right subtrees.

Read Full Article

like

19 Likes

For uninterrupted reading, download the app