# Boundary traversal of binary tree in java

If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions.

In this post, we will see boundary traversal of binary tree in java.

Lets understand boundary traversal of binary tree with example:

If you look closely to above diagram, boundary traversals can be divided into three essential parts

• Print left edge nodes (Excluding leaf nodes)
• Print leaf nodes
• Print right edge nodes (From bottom to top)

### Print left edge nodes (Excluding leaf nodes)

If you define boundary for left part, it is nothing but left child if present, otherwise right child.

### Print leaf nodes:

Its pretty simple operation.  Whenever you encounter leaf node, print it.

You may also refer print leaf nodes of binary tree.

### Print right edge nodes (From bottom to top) :

If you define boundary for right part, it is nothing but right child if present, otherwise left child. As we need to print bottom up, we will print the node while returning back from recursion stack.

Complete java program combining above three parts:

When you run above program, you will get below output:

## Java Binary tree tutorial:

Please go through java interview programs for more such programs.

import_contacts

## Related Posts

• 29 January

### Count subtrees with Sum equal to target in binary tree

Table of ContentsProblemSolutionWas this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see about how to count subtrees with Sum equal to target in binary tree Problem Given a Binary tree and an integer. You need to find […]

• 17 November

### Lowest Common Ancestor (LCA) for n-ary Tree

Table of ContentsProblemSolutionWas this post helpful? If you want to practice data structure and algorithm programs, you can go through Java coding interview questions. In this post, we will see about Lowest Common Ancestor for n-ary Tree. Problem Given a n-ary tree also known as a Generic Tree and also two nodes. You need to find […]

• 16 September

### Check if a binary tree is binary search tree or not in java

Table of ContentsFirst method:Second Method:Complete java program to check if Binary tree is binary search tree or not.Was this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to check if given binary tree is binary search […]

• 16 April

### Delete a node from binary search tree in java

Table of ContentsJava program to delete node in Binary search treeWas this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to delete a node from binary search tree. There are two parts to it. Search the […]

• 14 April

### Lowest Common Ancestor (LCA) of binary tree in java

Table of ContentsRecursive Algorithm (For nodes A and B):Java Binary tree tutorial:Was this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to find lowest common ancestor(LCA) of two nodes in binary tree. Lets understand with example. […]

• 07 April

### Reverse level order traversal of binary tree in java

Table of ContentsJava Binary tree tutorialWas this post helpful? If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. This is part of java binary tree tutorial. In this post, we will see about Reverse Level Order binary tree traversal in java. In previous post, we have […]