# 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

import_contacts

## Related Posts

• 18 June

### Maximum Number of Vowels in a Substring of Given Length

Table of ContentsApproach – 1 Generate All Substrings Using substring() MethodApproach – 2 Using Sliding Window Method (Linear Time Solution)Was this post helpful? In this article, we will look at an interesting problem related to the Strings and [Sliding-Window Algorithm](https://java2blog.com/sliding-window-maximum-java/ “Sliding-Window Algorithm”). The problem is : "Given a String we have to Find the Maximum […]

• 04 June

### Search for a range Leetcode – Find first and last position of element in sorted array

Table of ContentsApproach 1 (Using Linear Search)Approach 2 (Using Modified Binary Search-Optimal)Was this post helpful? In this article, we will look into an interesting problem asked in Coding Interviews related to Searching Algorithms. The problem is: Given a Sorted Array, we need to find the first and last position of an element in Sorted array. […]

• 30 April

### Convert Postfix to Infix in Java

Learn about how to convert Postfix to Infix in java.

• 30 April

### Convert Prefix to Postfix in Java

Learn about how to convert Prefix to Postfix in java.

• 16 April

• 29 November

### Top 100+ Java coding interview questions

Table of ContentsStringQuestion 1 : How to reverse a String in java? Can you write a program without using any java inbuilt methods?Question 2 : Write a java program to check if two Strings are anagram in java?Question 3 : Write a program to check if String has all unique characters in java?Question 4 : […]

1. John Williams says:

Found your blog. Its really nice on Binary tree in java programming. Its a great tutorial for the beginners. Really liked it. Thank you for all the information.

2. mythili says:

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

3. elf says:

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

4. Mahesh says:

Awesome …neat and simple to understand. Keep up your good work. Thanks for your blogs.

5. gaurav ranjan says:

Each and every explanation of urs is realy perfect.

6. Niraj Kumar Das says:

Awesome explainations…..All the concepts have been explained with such detail…Love this blog.

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.