From 6800c9aac9b65b9f4a62805a73b3185c11d2b62e Mon Sep 17 00:00:00 2001 From: Gyaneshwar Sunkara <52619288+gyaneshwar-sunkara@users.noreply.github.com> Date: Fri, 8 Sep 2023 00:53:51 -0400 Subject: [PATCH] BinaryTreeNode.js height() gives one less than tree's height. 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. --- src/data-structures/tree/BinaryTreeNode.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data-structures/tree/BinaryTreeNode.js b/src/data-structures/tree/BinaryTreeNode.js index 44c9390e4..dd68c4e30 100644 --- a/src/data-structures/tree/BinaryTreeNode.js +++ b/src/data-structures/tree/BinaryTreeNode.js @@ -26,7 +26,7 @@ export default class BinaryTreeNode { return 0; } - return this.left.height + 1; + return this.left.height; } /** @@ -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; } /**