Binary tree in java

If you want to practice data structure and algorithm programs, you can go through 100+ java coding 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:

Was this post helpful?

Comments

  1. thank u very much for giving clear explanation.could u please give explanation for generalised list .please if it possible

  2. You are the best blogger & teacher I have ever seen! You explain the core aspects of every subject and give no unnecessary detail.
    Congrats!! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *