This repository contains four classic binary tree algorithms implemented in Java. Each problem includes a reusable TreeNode
class, a well-commented solution, and a main()
test harness with sample cases.
-
β Same Tree
- Check if two binary trees are structurally identical and have the same values.
-
β Symmetric Tree
- Check whether a binary tree is a mirror of itself (i.e., symmetric around its center).
-
β Balanced Binary Tree
- Determine if a binary tree is height-balanced.
-
β Invert Binary Tree
- Invert a binary tree by swapping left and right children recursively.
Compile and run the program using any Java IDE or CLI.
javac BinaryTreeSolutions.java
java BinaryTreeSolutions
Same Tree: true
Symmetric Tree: true
Balanced Tree: true
Before invert (root.left.val): 2
After invert (root.left.val): 3
- Name: Mark Polycarp
- Email: markpollycarp@gmail.com
- Phone/Whatsapp: +44 7429 144739
Feel free to reach out for questions, collaborations, or feedback!