From f6a666ee9480ed3d9c21d0f4fcc61ab5879aa1a3 Mon Sep 17 00:00:00 2001 From: Sarbes04 <129949482+Sarbes04@users.noreply.github.com> Date: Tue, 9 Jan 2024 03:34:59 +0530 Subject: [PATCH] Update AVL.java The program was giving same value of height (3) on inserting elements >10 --- lectures/20-trees/code/AVL/AVL.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lectures/20-trees/code/AVL/AVL.java b/lectures/20-trees/code/AVL/AVL.java index b3080fcd3..950a265f2 100644 --- a/lectures/20-trees/code/AVL/AVL.java +++ b/lectures/20-trees/code/AVL/AVL.java @@ -90,8 +90,8 @@ public Node rightRotate(Node p) { c.right = p; p.left = t; - p.height = Math.max(height(p.left), height(p.right) + 1); - c.height = Math.max(height(c.left), height(c.right) + 1); + p.height = Math.max(height(p.left), height(p.right)) + 1; + c.height = Math.max(height(c.left), height(c.right)) + 1; return c; } @@ -103,8 +103,8 @@ public Node leftRotate(Node c) { p.left = c; c.right = t; - p.height = Math.max(height(p.left), height(p.right) + 1); - c.height = Math.max(height(c.left), height(c.right) + 1); + p.height = Math.max(height(p.left), height(p.right)) + 1; + c.height = Math.max(height(c.left), height(c.right)) + 1; return p; } @@ -159,4 +159,4 @@ private boolean balanced(Node node) { return Math.abs(height(node.left) - height(node.right)) <= 1 && balanced(node.left) && balanced(node.right); } -} \ No newline at end of file +}