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.

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:

4 Comments

  1. John Williams May 2, 2015
  2. mythili December 30, 2015
  3. elf July 29, 2016
  4. Mahesh October 2, 2016

Add Comment