# Tag Archives: Queue

Algorithms involving queues

## Find the left view of a binary tree.

Question: Given the root pointer to a binary tree, find the left view of the tree. Input: Sample Tree (Pointer to node 1 is given). Output: 1, 2, 4 At a single glance of the problem, we can understand that we need to perform a level order traversal on the tree. This is similar to finding the number… Read More »

## Given a binary tree, find the sum of all its elements without using recursion.

Question: Given the root pointer to a binary tree, find the sum of all its elements without using recursion. Input: Sample Tree (Pointer to node 1 is given). Output: Sum = 15 We discussed how to find the sum of all elements of a binary tree using recursion in this post. Given a binary tree, find the sum… Read More »

## Find the height of the binary tree without using recursion.

Question: Given the root pointer to a binary tree, find the height. Input: Sample Tree (Pointer to node 1 is given). Output: 3 We discussed the recursive method to find the height of the binary tree in this post- Find the height of the binary tree The non-recursive method will definitely require the level order traversal technique. The… Read More »

## Give an algorithm to find the number of full nodes in a binary tree.

Question: Given the root pointer to a binary tree, find the number of full nodes. Input: Sample Tree (Pointer to node 1 is given). Find the number of full nodes. Output: Number of full nodes = 3 According to the definition, the set of all nodes with both left and right child are called as full nodes. In… Read More »

## Give an algorithm to find the number of leaves in a binary tree.

Question: Given the root pointer to a binary tree, find the number of leaves. Input: Sample Tree (Pointer to node 1 is given). Find the number of leaves. Output: Number of leaves = 4 According to the definition, the set of all nodes whose both left and right child are null, are known as leaf nodes. In the… Read More »

## Write a program to find the deepest node in a binary tree?

Question: Given the root pointer to a binary tree, find the deepest node. Input: Sample Tree (Pointer to node 1 is given). Output: 5 According to the definition, the deepest node in a binary tree is the last element in the binary tree while performing a level order traversal. In the above case, therefore we have “5” as… Read More »

## Write an algorithm to find the size of a binary tree without using recursion.

Question: Given the root pointer to a binary tree, find its size. Input: Sample Tree (Pointer to node 1 is given). Find the size Output: Size = 7 We discussed how to find the size of a binary tree using the recursive method in this post:- Write an algorithm to find the size of a binary tree This… Read More »

## Write a program for inserting an element into a binary tree

Question: Given the root pointer to a binary tree, write a program to insert an element in it. Input: Sample Tree (Pointer to node 1 is given), Insert 7 Output: After insertion We are given a binary tree with random allocated values and the pointer to the root node is given. Since the given tree is a binary… Read More »

## Write a program to search an element in a binary tree without using recursion.

Question: Given the root pointer to a binary tree, find if an element is present in it. Input: Sample Tree (Pointer to node 1 is given), Search – 3 Output: Present We discussed how to find if an element exists in the binary tree in this post. Find if an element is present in a binary tree That… Read More »

## Find the maximum element in a binary tree without recursion.

Question: Given the root pointer to a binary tree, find the maximum element present in it. Input: Sample Tree (Pointer to node 1 is given) Output: Maximum = 9 We discussed how to find the maximum element in a binary tree using recursion in this post. Find maximum element in a binary tree That involved recursion. If recursion… Read More »