Author Archives: Gyaneshwar Pardhi

About Gyaneshwar Pardhi

Exploring the world and trying to know how can i involve to make this perfect. Gy@n!

Print Right View of a Binary Tree

Printing right view of binary tree is similar to printing left view of binary tree instead of printing each level first node print last node of each level. which will give us right view of a binary tree. below function … Continue reading

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

Print Left View of a Binary Tree

Below is a function which uses two queues which stores the current and next nodes value for printing left view of a binary tree. when we are swapping elements from next nodes queue to current node queue just print from … Continue reading

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

Find kth smallest element in Binary Search Tree

We can find kth smallest element in binary search tree using in order traversal because in order traversal of a binary search tree is a shorted list. above mention function is member function of my Binary Search Tree ADT class … Continue reading

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

Construct balanced Binary Search Tree using sorted Array

Here is complete program to construct balanced Binary Search Tree using sorted Array check in github A Developer Gy@n!

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

Check whether the given Binary Tree is a Binary Search Tree(BST) or not

To find out given binary tree is a BST or not just check BST property recursively for each node. Below is function which will accomplish this. But above function will give wrong result for below tree because we are just … Continue reading

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

Find Lowest Common Ancestor of two given nodes in Binary Search Tree

Assume we have following Binary Search Tree Then LCA of 8 and 12 will be 10 Here is function which will return LCA of two given nodes in a binary Search Tree above mention function is member function of my … Continue reading

Posted in c++, Data Structure, interview Question, Programming | 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

Find a given element in Binary Search Tree

This can be done using recursive function as well as non -recursive function . In binary search tree average worst case time complexity is O(logn) 1. Recursive function: 2. Non-recursive function : above mention functions are member function of my … Continue reading

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