Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions DataStructures/Trees/LevelOrderTraversal.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,14 +37,10 @@ int height(Node root)
return 0;
else
{
/* compute height of each subtree */
int lheight = height(root.left);
int rheight = height(root.right);

/* use the larger one */
if (lheight > rheight)
return(lheight+1);
else return(rheight+1);
/**
* Return the height of larger subtree
*/
return Math.max(height(root.left),height(root.right)) + 1;
}
}

Expand DownExpand Up@@ -75,4 +71,4 @@ public static void main(String args[])
System.out.println("Level order traversal of binary tree is ");
tree.printLevelOrder();
}
}
}