# Category: Trees

## Check If Given Undirected Graph is a tree

Objective: Given an undirected graph, Write an algorithm to determine whether its tree or not. An undirected graph is a tree if it has properties mentioned below There is no cycle present in the...

## Check the completeness of given binary tree | Set 2 – Using Level Order Traversal

Objective: Given a binary tree, write an algorithm to determine whether the tree is complete or not using Level order traversal. Earlier we had solved this problem by counting the number of nodes in...

## Check the completeness of given binary tree | Set 1 – Using Node Count

Objective: Given a binary tree, write an algorithm to determine whether the tree is complete or not.  Complete Binary Tree: A binary tree T with n levels is complete if all levels except possibly...

## Check if the given binary tree is Full or not.

Objective: Given a binary tree, write an algorithm to check if the tree is Full or not. Full binary tree:  A binary tree T is full if each node is either a leaf or...

## Count the number of nodes in a given binary tree

Objective: Given a binary tree, write an algorithm to count all the nodes in the tree. Example: Approach: Do postorder traversal. If the root is null return 0. (base case all well for the...

## Convert Binary Tree into Threaded Binary Tree

Objective: Given a binary tree write an algorithm to convert it into threaded binary tree. Note: Tree node has extra Boolean field to be used. In earlier article “Introduction to Threaded Binary Tree” we...

## Double Threaded Binary Tree Complete Implementation

In earlier article “Introduction to Threaded Binary Tree” we have seen what is threaded binary tree, types of it and what advantages it has over normal binary tree. In this article we will see...

## Single Threaded Binary Tree Complete Implementation

In earlier article “Introduction to Threaded Binary Tree” we have seen what is threaded binary tree, types of it and what advantages it has over normal binary tree. In this article we will see...

## Introduction to Threaded Binary Tree

What is Threaded Binary Tree?? A binary tree is threaded by making all right child pointers that would normally be null point to the inorder successor of the node (if it exists), and all left child pointers...

## Convert BST to Greater Sum Tree

Objective: Given a binary search tree (BST), convert it into greater sum tree. What is greater sum tree: Greater sum tree is a tree in which every node contains the sum of all the...

## Generate Maximum revenue by selling K tickets from N windows

Objective: Given ‘N’ windows where each window contains certain number of tickets at each window. Price of a ticket is equal to number of tickets remaining at that window. Write an algorithm to sell...

## Get the Sum of all left leaves in a Binary tree

Objective: Given a binary tree, find the sum of all the nodes which are left as well as leaves nodes. Example:     Approach: Approach is quite simple. Do the inorder traversal check if...

## Convert binary tree to its Sum tree

Objective: Given a binary tree, write an algorithm to convert it into its Sum tree. What is Sum tree: Sum tree of a binary tree, is a tree where each node in the converted...

## Binary Tree-Postorder Traversal – Non Recursive Approach

Objective: Given a binary tree, write a non recursive or iterative algorithm for postorder traversal. Example: Earlier we have seen “What is postorder traversal and recursive algorithm for it“, In this article we will...

## Binary Tree – Preorder Traversal – Non Recursive Approach

Objective: Given a binary tree, write a non recursive or iterative algorithm for preorder traversal. Example: Earlier we have seen “What is preorder traversal and recursive algorithm for it“, In this article we will...