Binary tree in java

If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions.
This is 1st part of java binary tree tutorial.
    Binary tree in java Binary tree preorder traversal Binary tree postorder traversal Binary tree inorder traversal Binary tree level order traversal Binary tree spiral order traversal Binary tree reverse level order traversal Binary tree boundary traversal Print leaf nodes of binary tree Count leaf nodes in binary tree get maximum element in binary tree Print all paths from root to leaf in binary tree Print vertical sum of binary tree in java Get level of node in binary tree in java Lowest common ancestor(LCA) in binary tree in java

A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child

Example of binary tree:

I have posted various programs on binary tree so that you can practice them for interviews and it will also help in understanding recursion.

Binary tree traversals:

PreOrder traversal - In PreOrder traversal,each node is processed before either of its sub-trees.In simpler words,Visit each node before its children.

InOrder traversal : In InOrder traversal,each node is processed between subtrees.In simpler words,Visit left subtree, node and then right subtree.

PostOrder traversal: In PostOrder traversal,each node is processed after subtrees traversal.In simpler words,Visit left subtree,  right subtree and then node.
Level order traversal : In Level order traversal, tree is traversed by each level. It is same as breadth first search.

Spiral/Zigzag order traversal : In spiral order traversal, tree is traversed in spiral shape.
Binary tree reverse level order traversal: It is similar to level order but in reverse
Binary tree boundary traversal : This traversal traverse boundary of binary tree

Other Binary tree programs:

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012