Find height of the Binary Tree

 Given a Binary Tree, write code to calculate the height of the tree. Height of the binary Tree is the total number of levels in the Binary Tree. For example, Height of a NULL tree is 0. If a tree has only 1 node (root node) then the height is 1 and so on … […]

Level of node in a Binary Tree

Given a Binary Tree and a pointer to the Node in that tree. Write a function to find level of Node in the Tree. For Example, in the below tree In the Tree on left side: Root Node (Node with value 10) is at level-0 Nodes with values 5 and 30 are at level-1 Nodes […]

Node with maximum value in a Binary search tree

Earlier, we have seen how to find the minimum element in a Binary Search Tree. Write a function which will return the maximum value in a binary search tree. For example: For the below Binary search tree, the function should return 40 Structure of the Node of the Tree is as given below: struct Node […]

Similar Trees

Write function to check whether two trees are similar or not. The signature of the function should be as shown below: /** * Function to check whether two trees are similar or not. * @param r1, r2: Pointer to root nodes of two trees. * Returns true(1) if the two are similar, else false(0) */ […]

deleting a tree

Given a binary tree, write code to delete the entire tree. Structure of the node is as given below: struct Node { int data; Node* lptr; // ptr to LEFT sub-tree Node* rptr; // ptr to RIGHT sub-tree };

syntax of main in C/C++ language

In C/C++ language, main function comes in different flavors as shown below: int main(); int main(int argc, char **argv); int main(int argc, char **argv, char **envp); int main(int argc, char **argv, char **envp, char **apple); What is the signature of main specified in the language standard ?

Find kth element in union of two arrays

Given two sorted arrays of size m and n respectively. Find the kth element in the merged result of A and B. For example, If the inputs (A, B & K ) are as given below Then the merged result of the two arrays will be And the 6th (K’th) element  = 8

Error in C language code

The function myfunc below is suppposed to print the size of array passed to it as parameter(arr). What do you think is the problem (if any) void myfunc(int arr[], int n) { printf(“Size of Array : %d”, sizeof(arr)); } int main() { int a[5] = {1, 2, 3, 4, 5}; myfunc(a, 5); }

Splitting a linked list

Given a linked list, write code to split it into two lists each containing the  alternate (odd-even) nodes from the original. If the original list is The It should split into two lists like below To make the final output look like (breaking the original list in two sublists)

Finding middle element of Linked list using one loop

Write a function which will accept a pointer to the head of the linked list and returns a pointer to the middle node of the list. If the list given is 2 -> 3 -> 5 -> 1 -> 4 -> 8 -> 10 Then the function should return a pointer to Node with value 1. […]