Skip to content

Commit

Permalink
BinaryTreeNode.js height() gives one less than tree's height.
Browse files Browse the repository at this point in the history
The height of the tree is the number of edges in the tree from the root to the deepest node. 

height right now gives one less than the total number of the edges, small tweek made will fix it.
  • Loading branch information
gyaneshwar-sunkara committed Sep 8, 2023
1 parent 76617fa commit 6800c9a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/data-structures/tree/BinaryTreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class BinaryTreeNode {
return 0;
}

return this.left.height + 1;
return this.left.height;
}

/**
Expand All @@ -37,14 +37,14 @@ export default class BinaryTreeNode {
return 0;
}

return this.right.height + 1;
return this.right.height;
}

/**
* @return {number}
*/
get height() {
return Math.max(this.leftHeight, this.rightHeight);
return Math.max(this.leftHeight, this.rightHeight) + 1;
}

/**
Expand Down

0 comments on commit 6800c9a

Please sign in to comment.