Binary Tree


Question 1
Consider the C function foo and the binary tree shown.

typedef struct node {
   int val;
   struct node *left, *right;
} node;

int foo(node *p) {
   int retval;
   if (p == NULL)
       return 0;
else {
     retval = p->val + foo(p->left) + foo(p->right);
     printf("%d ", retval);
     return retval;
     }
}



When foo is called with a pointer to the root node of the given binary tree, what will it print?
A
3 8 5 13 11 10
B
3 5 8 10 11 13
C
3 8 16 13 24 50
D
3 16 8 50 24 13
GATE CSE 2023   Data Structure
Question 2
Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.

The value of |A-B| is _____________
A
3
B
4
C
1
D
2
GATE CSE 2021 SET-2   Data Structure


Question 3
The post-order traversal of binary tree is ACEDBHIGF. The pre-order traversal is
A
A B C D E F G H I
B
F B A D C E G I H
C
F A B C D E G H I
D
A B D C E F G I H
ISRO CSE 2020   Data Structure
Question 4
Let T be a full binary tree with 8 leaves. (A full binary tree has every level full.) Suppose two leaves a and b of T are chosen uniformly and independently at random. The expected value of the distance between a and b in T (i.e., the number of edges in the unique path between a and b) is (rounded off to 2 decimal places) ___________ .
A
2.5
B
4.25
C
6.5
D
3.75
GATE CSE 2019   Data Structure
Question 5


Which traversals of Tree-1 and Tree-2, respectively, will produce the same sequence?
A
Preorder, postorder
B
Postorder, inorder
C
Postorder, preorder
D
None of these
ISRO CSE 2018   Data Structure


There are 5 questions to complete.

5 thoughts on “Binary Tree”

Leave a Comment