0% found this document useful (0 votes)
8 views3 pages

Tree - DPP 03 (Of Lec 04)

The document contains a Data Structure DPP focused on trees, including questions about unlabelled and labelled binary trees, binary search trees, and tree traversals. It provides multiple-choice questions and answers, along with hints and solutions for each question. The answer key and additional resources for further learning are also included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Tree - DPP 03 (Of Lec 04)

The document contains a Data Structure DPP focused on trees, including questions about unlabelled and labelled binary trees, binary search trees, and tree traversals. It provides multiple-choice questions and answers, along with hints and solutions for each question. The answer key and additional resources for further learning are also included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1

Branch : CSE & IT Batch : Hinglish


Data Structure
Tree DPP 03

[NAT] if(t==NULL) return 1;


1. The number of unlabelled binary trees possible with else if(t->left==NULL && t->right==NULL)
four nodes is _________. return 1;
else if
[NAT] ((t → left → data < t->data) && (t → right → data > t-
2. The number of labelled binary trees possible with the >data))
nodes-10, 30, 25, 40 is _________. return func(t->left) && func(t->right);
else
[NAT] return 0;
3. The number of binary search trees possible with the }
nodes-10, 30, 25, 40 is _________. Assume t contains the address of the root node of a tree.
The function-
[MCQ] (a) Returns 1 if the given tree is a Binary Search Tree.
4. The pre-order traversal of a binary search tree is given (b) Returns 0 if the given tree is a complete binary
as- tree.
7, 3, 2, 1, 5, 4, 6, 8, 10, 9, 11 (c) Returns 0 if the given tree is a Binary Search Tree.
The post-order traversal of the above binary tree is- (d) Returns 1 if the given tree is a complete binary
(a) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 tree.
(b) 1, 2, 4, 6, 5, 3, 9, 11, 10, 8, 7
(c) 1, 2, 4, 5, 6, 3, 9, 10, 11, 8, 7 [MCQ]
(d) 11, 9, 10, 8, 6, 4, 5, 1, 2, 3, 7 7. Consider the following function:
struct treenode{
[MCQ] struct treenode *left;
5. Consider the following two statements: int data;
Statement P: The last elements in the pre-order and in- struct treenode *right;
order traversal of a binary search tree are always same. };
Statement Q: The last elements in the pre-order and in- struct treenode * f(struct treenode *t, int x){
order traversal of a binary tree are always same. if(t==NULL) return NULL;
Which of the following tree is/are CORRECT? elseif(x==t->data) return ______a______;
(a) Both P and Q only else if (x<t->data) return ______b______;
(b) Neither P nor Q else return ______c______;
(c) Q only }
(d) P only Assume t contains the address of the root node of a
[MCQ] binary search tree. The function finds an element x in
6. Consider the following function: the BST and returns the address of the node if found.
struct treenode{ Which of the following statement(s) is/are CORRECT?
struct treenode *left; (a) a: NULL ; b: f(t->left, x) ; c: f(t->right, x)
int data; (b) a: t ; b: f(t->right, x) ; c: f(t->left, x)
struct treenode *right; (c) a: NULL ; b: f(t->right, x) ; c: f(t->left, x)
}; (d) a: t ; b: f(t->left, x) ; c: f(t->right, x)
int func (struct treenode *t){
2

Answer Key
1. (14) 5. (b)
2. (336) 6. (a)
3. (14) 7. (d)
4. (b)
3

Hint & Solutions


1. (14)
Number of unlabelled binary trees possible with 4
nodes
1 (2  4)!
= 
4 + 1 4! 4!
1 8!
= 
5 4! 4!
2
1 8 7 6  5
= 
5 4  3  2 1
= 14 Post-order traversal-
1 2 4 6 5 3 9 11 10 8 7
2. (336)
Number of labelled binary trees possible with 5. (b)
4 nodes- P: INCORRECT. The last elements in the pre-order
= 4! × Number of unlabelled binary trees with and in-order traversal of a binary search tree are not
4 nodes always same.(It violates for skewed BSTs)
= 4! × 14 Q: INCORRECT. The last elements in the pre-order
= 336 and in-order traversal of a binary tree are not always
same.
3. (14)
6. (a)
Number of BSTs with 4 = Number of unlabelled
binary trees with nodes The function- Returns 1 if the given tree is a Binary
Search Tree.

4. (b)
7. (d)
Pre-order traversal of BST:
struct treenode{
7 3 2 1 5 4 6 8 10 9 11
struct treenode *left;
In-order traversal of BST:
int data;
1 2 3 4 5 6 7 8 9 10 11
struct treenode *right;
Tree is constructed as-
};
void f(struct treenode *t, int x){
if(t==NULL) return NULL;
elseif(x==t->data) return t;
else if (x<t->data) return f(t->left, x);
else return f(t->right, x);
}

Any issue with DPP, please report by clicking here:- https://forms.gle/t2SzQVvQcs638c4r5


For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if

PW Mobile APP: https://smart.link/7wwosivoicgd4

You might also like