Tree
Nature
Simple Tree Construction
import java.lang.*;
class Node {
int key;
Node left;
Node right;
Node(int k) {
key = k;
left = right = null;
}
}
class Main {
public static void main(String[] args) {
Node root = new Node(10);
root.left = new Node(20);
root.right = new Node(30);
root.left.left = new Node(40);
}
}In Order Tree Traversal
Pre Order Traversal
Post Order Traversal
Height of Binary Tree
Print Nodes at K distance
Level Order Traversal
Level Order Traversal Line by Line (Part 1)
Level Order Traversal Line by Line (Part 2)
Size of Binary Tree
Maximum in Binary Tree
Print Left View of Tree ( Recursively )
Print Left View of Tree ( Iteratively )
Children Sum Property
Check if tree is balanced
Max Width Binary Tree
Convert Binary Tree to Doubly Linked List
Construct Binary Tree from Inorder and Preorder
Tree Traversal in Spiral Form (First Method)
Tree Traversal in Spiral Form (Second Method)
Diameter of a Binary Tree
LCA of Binary Tree
Burn a Binary Tree from a Leaf
Count nodes in a Complete Binary Tree
Serialize a Binary Tree
DeSerialize a Binary Tree
// TODO : iterative pre order traversal and efficient solution to it
Last updated