tree data structure

Leetcode 110

Learn how to determine whether a Binary Tree is height-balanced using Java and Data Structures concepts. In this guide, we start from basic tree fundamentals, understand the brute-force approach, and then move toward an optimized O(N) solution using postorder traversal. This tutorial is perfect for beginners preparing for coding interviews and looking to master recursion and tree depth calculations in a clear, practical way.

Leetcode 110 Read More »

inorder tree traversal

Binary tree Inorder traversal

Binary In-order Traversal Recursive Approach class Solution { public List inOrderTaversal(TreeNode root){ List result = new ArralyList(); inOrder(root, result); return result; } public void inOrder(TreeNode root, List result) { if (root != null) { inOrder(root.left, result); result.add(root.value); inOrder(root.right); } return; } } Time Complexity: O(n); Space Complexity: O(n); Morris Traversal Approach class Solution { public

Binary tree Inorder traversal Read More »

Dare To Dream