GATE-CS-2004
Question 1 |
have well indented programs | |
be able to infer the flow of control from the compiled code | |
be able to infer the flow of control from the program text | |
avoid the use of GOTO statements |
Discuss it
Question 2 |
void swap (int a, int b) { int temp; temp = a; a = b; b = temp; }In order to exchange the values of two variables x and y.
Call swap (x, y) | |
Call swap (&x, &y) | |
swap(x,y) cannot be used as it does not return any value | |
swap(x,y) cannot be used as the parameters are passed by value |
Discuss it
Question 3 |
(top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1) | |
top1 + top2 = MAXSIZE | |
(top1= MAXSIZE/2) or (top2 = MAXSIZE) | |
top1= top2 -1 |
Discuss it
Question 4 |
2 | |
3 | |
4 | |
6 |
Discuss it
Question 5 |
queue | |
stack | |
tree | |
list |
Discuss it
Question 6 |
preorder traversal | |
inorder traversal | |
depth first search | |
breadth first search |
Discuss it
Question 7 |
1. 9679, 1989, 4199 hash to the same value 2. 1471, 6171 hash to the same value 3. All elements hash to the same value 4. Each element hashes to a different value
1 only | |
2 only | |
1 and 2 only | |
3 or 4 |
Discuss it
Question 8 |
1. P → Q R 2. P → Q s R 3. P → ε 4. P → Q t R r
1 only | |
1 and 3 only | |
2 and 3 only | |
3 and 4 only |
Discuss it
Question 9 |
Edit-time | |
Compile-time | |
Link-time | |
Load-time |
Discuss it
Question 10 |
Consider the grammar rule E → E1 - E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub expression, in order to get the shortest possible code
E1 should be evaluated first | |
E2 should be evaluated first | |
Evaluation of E1 and E2 should necessarily be interleaved | |
Order of evaluation of E1 and E2 is of no consequence |
Discuss it
E -> E1 - E2 Given that E1 and E2 don't share any sub expression, most optimized usage of single user register for evaluation of this production rule would come only when E2 is evaluated before E1. This is because when we will have E1 evaluated in the register, E2 would have been already computed and stored at some memory location. Hence we could just use subtraction operation to take the user register as first operand, i.e. E1 and E2 value from its memory location referenced using some index register or some other form according to the instruction. Hence correct answer should be (B) E2 should be evaluated first.