Interview Questions
Please post your answer in comments if you have a better solution.
Wednesday, August 15, 2007
Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)!
›
This C code will create a new mirror copy tree. mynode *copy(mynode *root) { mynode *temp; if(root==NULL)return(NULL); temp = (my...
323 comments:
Write a C program to compute the maximum depth in a tree?
›
int maxDepth(struct node* node) { if (node==NULL) { return(0); } else { int leftDepth = maxDepth(node->left); int ...
7 comments:
Write a C program to find the mininum value in a binary search tree.
›
Here is some sample C code. The idea is to keep on moving till you hit the left most node in the tree int minValue(struct node* node) { st...
10 comments:
Write C code to determine if two trees are identical .
›
Here is a C program using recursion int identical(struct node* a, struct node* b) { if (a==NULL && b==NULL){return(true);} else ...
5 comments:
Write a C program to delete a tree (i.e, free up its nodes)
›
Free up the nodes using Postorder traversal!.
5 comments:
Write a C program to determine the number of elements (or size) in a tree.
›
int tree_size(struct node* node) { if (node==NULL) { return(0); } else { return(tree_size(node->left) + tree_size(node-...
4 comments:
Write a C program to find the depth or height of a tree.
›
Here is some C code to get the height of the three tree_height(mynode *p) { if(p==NULL)return(0); if(p->left){h1=tree_height(p->...
222 comments:
›
Home
View web version