Tag Archives: tree

Program to display bottom view of binary tree

A Developer Gy@n!

Posted in Algorithm, c++, Data Structure, interview Question | Tagged , | Leave a comment

Delete a given node in Binary Search Tree

Deletion of a node in Binary Tree is easy because we don’t bother about the relationship between children and parents their value may be less or greater then. In Binary Search Tree when we delete A node after that we … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , , , | Leave a comment

Find minimum element in the Binary Search Tree

1. Recursive Function: 2. Non-Recursive Function: above mention functions are member function of my Binary Search Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , , , | Leave a comment

Find maximum element in the Binary Search Tree

1. Recursive function : 2.Non-Recursive function: above mention functions are member function of my Binary Search Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , , , | Leave a comment

Function to print all Ancestors of a given node in Binary Tree

above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to calculate the sum of all elements of a binary tree

above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to check there is path in the binary tree with a given sum

This function have trick call same function again for children nodes with remaining sum, at the end if sum become zero ie there is the path for a given sum. above mention function is member function of my Tree ADT … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to print all root to leaf node path of a binary tree

Here is complete function to print all root to leaf node path comments describe well this function. above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , | 1 Comment

Function to find level with maximum sum of a binary tree

Function to find out level with max sum. above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to find diameter of a binary tree

Diameter of a binary tree is longest path between two nodes.To calculate the diameter of a binary tree first calculate the diameter of left sub tree and then right sub tree so current node diameter will be max (diameter of … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to check if two Binary Tree are Identical or not

1. This can done easily using recursive method. Here is complete function . above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in Algorithm, c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to count leaf nodes in the Binary Tree

1.Non-recursive method: use two queues one for current level and another for next level.same function can use to calculate to find full nodes and half nodes count also. we have to change the condition for count increment,I added those condition … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , , | Leave a comment

Function to find deepest node in Binary Tree

This is similar to find the height of binary tree non-recursive method.Deepest node will be the last node in the current level queue. above mention function is member function of my Tree ADT class you can check complete program here … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Function to find Height of Binary Tree

we can calculate Height of binary tree using recursion and without recursion also. 1.recursive Method: get the height of left subTree and right subTree then return the max(hightOfLeftSubTree,heightOfRightSubTree)+1. 2. Non-recursive Method: create two queues which store current level and next … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , , , | 1 Comment

Printing a Binary Tree in Zig Zag Level-Order

Printing binary tree Elements in zig zag order is little bit tricky.assume we have binary tree as below. than output : 1 3 2 4 5 6 7 printing binary tree Elements in zig zag order require two stacks . … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , | Leave a comment

Print the Binary Tree elements in reverse level order program

Let’s say we have a binary tree as below Now we want to print the binary tree elements like 4 5 6 7 2 3 1. So whenever we need to traverse level order we need a queue and since … Continue reading

Posted in Algorithm, c++, Data Structure, interview Question, Programming | Tagged , , | 2 Comments

Function to find the size of Binary Tree

1.using recursion: size of binary tree =(size of left child+1+ size of right child). 2.Non-recursive approach : above mention function is member function of my Tree ADT class you can check complete program here A Developer Gy@n!

Posted in Algorithm, c++, Data Structure, interview Question, Programming | Tagged , , , | Leave a comment

Insert Elements in Binary Tree

It’s always easy to store elements in binary search tree(BST) because of its property and generally we forget about how to add elements in binary tree not in binary search tree(BST). Here is function which we can use to add … Continue reading

Posted in c++, Data Structure, interview Question, Programming | Tagged , , | Leave a comment