Binary Tree

Check leaf nodes of binary tree are at same level – BFS / 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:

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.

Scroll to Top