DataStructure

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.

Scroll to Top