• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE-CS-2004

Question 1

The goal of structured programming is to:
  • 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

Question 2

Consider the following C function C
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

Question 3

A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full” is
  • (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
  • top1 + top2 = MAXSIZE
  • (top1= MAXSIZE/2) or (top2 = MAXSIZE)
  • top1= top2 -1

Question 4

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?
  • 2
  • 3
  • 4
  • 6

Question 5

The best data structure to check whether an arithmetic expression has balanced parentheses is a
  • queue
  • stack
  • tree
  • list

Question 6

Level order traversal of a rooted tree can be done by starting from the root and performing
  • preorder traversal
  • inorder traversal
  • depth first search
  • breadth first search

Question 7

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true?

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

Question 8

Which of the following grammar rules violate the requirements of an operator grammar ? P, Q, R are nonterminals, and r, s, t are terminals.
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

Question 9

Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at
  • Edit-time
  • Compile-time
  • Link-time
  • Load-time

Question 10

Consider the grammar rule E → E1 - E2 for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction operation requires the first operand to be in the register. If E1 and E2 do not have any com­mon 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

There are 90 questions to complete.

Last Updated :
Take a part in the ongoing discussion