Connect nodes at same level (set next sibling)-binary tree DFS/example

Given a binary tree, we need to connect the nodes lying at same level. We have already discussed about the tree traversal using breadth first search algorithm, where we are printing the nodes level by level. By the end of this article we will achieve the same result using next sibling reference. In binary tree, we generally have following information.

Check binary tree is Quasi-Isomorphic of other tree in java (DFS / Example)

We are given two binary tree, we need to find out whether one binary tree is Quasi Isomorphic of other binary tree. Quasi Isomorphic tree? Trees are considered to Quasi isomorphic where we concerned about the structures. The structure of both tree either should be identical or obtained by swapping (or Mirror) its children.

Check given binary trees are Isomorphic in java (recursive / examples)

We are given two binary tree, we need to find out whether one binary tree is Isomorphic of other binary tree. What is Isomorphic meaning? As per English dictionary meaning is “being of identical or similar form, shape, or structure”. By apply above definition to our problem statement, If given binary have identical or similar form or shape or structure to another binary tree, we can say that trees are isomorphic.

Find level of node in binary tree – BFS (non-recursive) & example

What is level in binary tree?
Level is distance or hops of node with respect to root node. The root node is considered to be at level 0, so children of root node will be at level 1 (level of root node + 1). So, we can calculate the level of all the nodes in binary tree.
As an example, consider the tree:

Find maximum width of binary tree using BFS (with example)

Given the binary tree, We need to find the maximum width of binary tree. What is width of binary tree? The number of nodes at any level provides the width of binary tree (at that level). We will find the width at each level and maximum among these widths will be our desired output.

Find InOrder predecessor in binary search tree (BST) in java (examples)

Predecessor of any node is the previous node of binary traversal. Let us take an example to understand the inorder predecessor in binary search tree. We have already discussed about the inorder successor. The logical flow of inorder predecessor and inorder successor is same. If we understand any one of them, other can be solved in similar manner.

Find maximum sum, root to leaf path in binary tree (Java/ recursive/ example)

Given the binary tree, There are multiple paths (equal to number of leaf nodes) exist from root to leaf nodes, We need to calculate the sum of all nodes in each root to leaf path, then we need to print the maximum sum and the corresponding path. Let us take the example to elaborate our problem statement.

Number of nodes or size of binary tree in java (DFS / examples)

Given the binary tree, we need to find number of nodes in the given binary tree. To count the number of nodes in binary tree, we need to visit all the nodes at least once. We have counted the number of nodes without recursion using level order traversal in this post.

Spiral or Zigzag binary tree traversal in java (BFS & example)

Breadth First Traversal or Level Order Traversal: As name suggests, in tree traversal, where in we are traversing the breadth of tree. In this traversal, we traverse all nodes across the breadth of binary tree. In level order traversal we perform following procedure:
Traverse the binary tree level by level
At each level we go left to right

Scroll to Top