GATE 2017 (Session 1)
64 questions
MCQ 44 · NAT 201-mark 30 · 2-mark 34
Questions 16–20 of 64
Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are :
Note: The height of a tree with a single node is 0.
Note: The height of a tree with a single node is 0.
Answer: (B)
Let us check both cases:
- Minimum height: take a complete tree. 15 nodes fill levels 0 to 3 (1 + 2 + 4 + 8) so the height is 3.
- Maximum height: take a chain of 15 nodes so the height is 14.
Answer: 3 and 14 respectively
- Minimum height: take a complete tree. 15 nodes fill levels 0 to 3 (1 + 2 + 4 + 8) so the height is 3.
- Maximum height: take a chain of 15 nodes so the height is 14.
Answer: 3 and 14 respectively
The n-bit fixed-point representation of an unsigned real number real X uses f bits for the fraction part. Let i=n-f. The range of decimal values for X in this representation is
Answer: (D)
The number has i integer bits and f fraction bits.
The smallest value is 0, when all bits are 0.
The largest value is when all bits are 1: .
Answer: 0 to
The smallest value is 0, when all bits are 0.
The largest value is when all bits are 1: .
Answer: 0 to
Consider the C code fragment given below.
typedef struct node {
int data;
node* next ;
} node;
void join (node* m, node* n) {
node* p=n ;
while (p->next ! =NULL){
p = p -> next ;
}
p-> next = m;
} Assuming that m and n point to valid NULL- terminated linked lists, invocation of join willAnswer: (B)
The function join moves to the last node of list n and then links that node to m. If list n is empty (n = NULL), then p next is a null pointer dereference. In every other case, list m gets appended at the end of list n.
(The paper writes node* next inside the struct, which is not valid C; it would need struct node *next. The question is meant as if it were valid.)
Answer: either cause a null pointer dereference or append list m to the end of list n
(The paper writes node* next inside the struct, which is not valid C; it would need struct node *next. The question is meant as if it were valid.)
Answer: either cause a null pointer dereference or append list m to the end of list n
When two 8-bit numbers and in 2's complement representation (with and as the least significant bits ) are added using a ripple-carry adder, the sum bits obtained are and the carry bits are . An overflow is said to have occurred if
Answer: (C)
In 2's complement, overflow occurs when both numbers have the same sign and the sum has the opposite sign:
- Both numbers negative () and the sum is positive, with ; or
- Both numbers positive () and the sum is negative, with .
Together, this gives the condition .
Answer: Option 3
- Both numbers negative () and the sum is positive, with ; or
- Both numbers positive () and the sum is negative, with .
Together, this gives the condition .
Answer: Option 3
Consider the following context-free grammar over the alphabet = {a,b,c} with S as the start symbol.
SabScT|abcT
TbT|b
Which one of the following represents the language generated by the above grammar ?
SabScT|abcT
TbT|b
Which one of the following represents the language generated by the above grammar ?
Answer: (B)
produces with .
Each use of adds "ab" on the left and "cT" on the right, and the last step adds one more such pair. After pairs the string is
with copies of .
Every is a separate non-terminal, so each one is replaced by on its own, with its own . So the language is
with .
This rules out the others. (A) fixes every . (C) forces all to be equal. (D) has blocks of , but the grammar always gives exactly c's. For example, is in the language but its two blocks differ, so it is in neither (C) nor (D).
Answer: (B)
Each use of adds "ab" on the left and "cT" on the right, and the last step adds one more such pair. After pairs the string is
with copies of .
Every is a separate non-terminal, so each one is replaced by on its own, with its own . So the language is
with .
This rules out the others. (A) fixes every . (C) forces all to be equal. (D) has blocks of , but the grammar always gives exactly c's. For example, is in the language but its two blocks differ, so it is in neither (C) nor (D).
Answer: (B)