Binary Tree Traversals (Inorder, Preorder and Postorder)
2023-06-15 16:51:38
What is Binary Tree?
Each node of the tree has at most two children - a left and a right child.
Complete Binary Tree
All the levels of the tree are filled completely except the lowest level nodes which are filled from as left as possible.
Perfect Binary Tree
A binary tree of height h having the maximum number of nodes is a perfect binary tree.
Full Binary Tree
A full Binary tree is a special type of binary tree in which every parent node/internal node has either two or no children. It is also known as a proper binary tree.
Tree Traversal
Iterative Preorder Traversal
1 | public static List<Integer> preorderTraversal(TreeNode root) { |
Iterative Inorder Traversal
1 | public static List<Integer> inorderTraversal(TreeNode root) { |
Iterative Postorder Traversal
1 | //postorder traversal:-> right, left, root |