First time user?    |

#### Select chapter

functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
trees (1.papers)
basics (5.papers)
Hide

# c trees interview questions and answers

1
```what is below data structure representing to?

class sibtreenode{
object item;
sibtreenode parent;
sibtreenode firstchild; //first left node
sibtreenode nextsibling;//immediate next right sibling node for this node.
}```
1. `it is representing a non rooted binary tree`
2. `it is representing rooted binary tree`
3. `it is representing rooted tree`
4. `it is both a binary tree and normal tree, both are rooted.`
Share
Share
Share
Share
Share
6
```example code for finding a node in a tree in c:

what is below function doing?
public Object find(Object k){
BinaryTreeNode node = root;
while(node != null){
int comp = k.comparedTo(node.entry.key());
if(comp <0){
node = node.left;
}else if(comp>0){
node = node.right;
}else{
return node.entry;
}
}
return null;
}```
1. `it is trying to find if a value is available in a binary tree.`
2. `it is trying to find if a value is available in a binary search tree.`
3. `it is trying to find if a value is available in a non binary tree.`
4. `all are correct`
Share
7
```how to remove a node with key k in a binary search tree?

Assumption 1: that node has only maximum one child.
Assumption 2: that node is n which is having key k.```
1. `if n has no children, detach it from its parent.`
2. `if n has one child, move n's child up to take n's place.`
3. `both option 1 and 2 are correct.`
4. `both option 1 and 2 are reversed.`
Share
8
```how to remove a node with key k in a binary search tree?

Assumption: that node has 2 children.```
1. `if n has 2 children, let x be node in n's left sub tree with the smallest key. remove x (since x has no left child and is easily rmvd). and now  replace n's key with x's key.`
2. `if n has 2 children, let x be node in n's right sub tree with the largest key. remove x (since x has no left child and is easily rmvd). and now  replace n's key with x's key.`
3. `if n has 2 children, let x be node in n's right sub tree with the smallest key. remove x (since x has no left child and is easily rmvd). and now  replace n's key with x's key.`
4. `if n has 2 children, let x be node in n's left sub tree with the largest key. remove x (since x has no left child and is easily rmvd). and now  replace n's key with x's key.`
Share
9
```What is the time complexity of inserting set of elements into a binary search tree in the same order?

Assumption 1: n is the no of nodes in that tree.
Assumption 2: set of elements which are to be inserted are already in sorted order
```
1. `if we have set of elements which are already sorted, and try to insert them into the binary search tree in the same order, complexity is O(n)`
2. `if we have set of elements which are already sorted, and try to insert them into the binary search tree in the same order, complexity is  O(log n)`
3. `if we have set of elements which are already sorted, and try to insert them into the binary search tree in the same order, complexity is  O(n log n)`
4. `if we have set of elements which are already sorted, and try to insert them into the binary search tree in the same order, complexity is  O(n^2)`
Share
Share
11
```Which of the below properties are true about a rooted tree?

i. leaf node : will not have children
ii. siblings : two nodes having same parent```
1. `i`
2. `ii`
3. `option i is right option ii is wrong`
4. `both option i and ii are correct.`
Share
Share
Share
14
`Tree traversal: which of the below statements are wrong about a rooted tree traversal?`
1. `tree traversal means : visiting each node in the tree`
2. `tree traversal means : visiting each node only once in the tree`
3. `traversal takes O(n) time complexity`
4. `inorder traversal is applicable to only binary trees.`
Share
Share
16
`preorder traversal example in c: which of the below algorithms is correct for preorder traversal in c?`
1. ```public void order(){
if(firstchild != null){
firstchild.order();
}
this.visit();//print this node
if(nextsibling != null){
nextsibling.order();
}
}```
2. ```public void order(){
if(firstchild != null){
firstchild.order();
}
if(nextsibling != null){
nextsibling.order();
}
this.visit();//print this node
}```
3. ```public void order(){
this.visit();//print this node
if(nextsibling!= null){
nextsibling.order();
}
if(firstchild!= null){
firstchild.order();
}
}```
4. ```public void order(){
this.visit();//print this node
if(firstchild != null){
firstchild.order();
}
if(nextsibling != null){
nextsibling.order();
}
}```
Share
17
`postorder traversal example in c: which of the below algorithms is correct for postorder traversal in c?`
1. ```public void postorder(){
this.visit();//print this node
if(firstchild != null){
firstchild.postorder();
}
if(nextsibling != null){
nextsibling.postorder();
}
}
}```
2. ```public void postorder(){
if(firstchild != null){
firstchild.postorder();
}
this.visit();//print this node
if(nextsibling != null){
nextsibling.postorder();
}
}
}```
3. ```public void postorder(){

if(firstchild != null){
firstchild.postorder();
}
if(nextsibling != null){
nextsibling.postorder();
}
this.visit();//print this node
}
}```
4. ```public void postorder(){
if(nextsibling != null){
nextsibling.postorder();
}

if(firstchild != null){
firstchild.postorder();
}
this.visit();//print this node
}
}```
Share
Share
Share