Master TreeHierarchical Structures
Learn tree traversals, BST operations, and balanced trees through interactive visualizations.
Choose OperationStart Visualizing
Click on any operation to see it in action with interactive step-by-step visualization
Tree Traversal
EasyInorder, Preorder, Postorder, Level-order traversals.
O(n)BST Insertion
EasyInsert node maintaining BST property.
O(log n)BST Deletion
MediumDelete node with proper restructuring.
O(log n)BST Search
EasyFind node in binary search tree.
O(log n)Tree Height
EasyCalculate maximum depth of tree.
O(n)Check Balanced
MediumVerify if tree is height-balanced.
O(n)Lowest Common Ancestor
MediumFind LCA of two nodes in tree.
O(log n)Tree Diameter
MediumFind longest path between any nodes.
O(n)Mirror Tree
EasyCreate mirror image of tree.
O(n)Serialize/Deserialize
HardConvert tree to/from string representation.
O(n)Path Sum
MediumFind paths with given sum.
O(n)Tree Views
MediumTop, bottom, left, right views of tree.
O(n)Kth Ancestor
HardFind kth ancestor of given node.
O(log n)Boundary Traversal
MediumPrint boundary nodes of tree.
O(n)Construct from Traversals
HardBuild tree from inorder/preorder/postorder.
O(n)Each operation includes interactive visualization, code implementation, and complexity analysis
All Tree OperationsDetailed Overview
Explore 15 tree operations with complexity analysis, pros & cons, and use cases
Tree TypesComparison
Compare Binary Tree, BST, and AVL Tree
| Operation | Binary Tree | BST | AVL Tree | Notes |
|---|---|---|---|---|
| Search | O(n) | O(log n)* | O(log n) | *Average for balanced BST |
| Insert | O(1) | O(log n)* | O(log n) | At specific position/node |
| Delete | O(n) | O(log n)* | O(log n) | Find and remove |
| Min/Max | O(n) | O(log n)* | O(log n) | Leftmost/rightmost |
| Height | O(n) | O(n) | O(log n) | Maintained in AVL |
| Traversal | O(n) | O(n) | O(n) | Visit all nodes |
| Space | O(n) | O(n) | O(n) | Node storage |
| Balance | No | No | Yes | Self-balancing property |
Tree Characteristics
Binary Tree: At most 2 children
No ordering: Any structure allowed
Use: Expression trees, heaps
BST: Left < Node < Right
Ordered: Inorder gives sorted
Use: Searching, sorting
AVL: Self-balancing BST
Balanced: |left-right| ≤ 1
Use: Guaranteed O(log n)