• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Gate IT 2007

Question 21

A depth-first search is performed on a directed acyclic graph. Let d[u] denote the time at which vertex u is visited for the first time and f[u] the time at which the dfs call to the vertex u terminates. Which of the following statements is always true for all edges (u, v) in the graph ?
  • d[u] < d[v]
  • d[u] < f[v]
  • f[u] < f[v]
  • f[u] > f[v]

Question 22

What is the largest integer m such that every simple connected graph with n vertices and n edges contains at least m different spanning trees?
  • 1
  • 2
  • 3
  • n

Question 23

Consider n jobs J1, J2,......Jn such that job Ji has execution time ti and a non-negative integer weight wi. The weighted mean completion time of the jobs is defined to be [Tex] \\frac{\\sum_{i=1}^{n} w_i T_i}{\\sum_{i=1}^{n} w_i}[/Tex], where Ti is the completion time of job Ji. Assuming that there is only one processor available, in what order must the jobs be executed in order to minimize the weighted mean completion time of the jobs?
  • Non-decreasing order of ti
  • Non-increasing order of wi
  • Non-increasing order of witi
  • None-increasing order of wi/ti

Question 24

The function f is defined as follows: 

C
int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1. 
ii. The function f terminates for infinitely many different values of n ≥ 1. 
iii. The function f does not terminate for finitely many different values of n ≥ 1. 
iv. The function f does not terminate for infinitely many different values of n ≥ 1. 
Which one of the following options is true of the above?

  • (i) and (iii)

  • (i) and (iv)

  • (ii) and (iii)

  • (ii) and (iv)

Question 25

Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5.

  • 5

  • 6

  • 7

  • 10

Question 26

Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are: 
i. isEmpty (Q) — returns true if the queue is empty, false otherwise. 
ii. delete (Q) — deletes the element at the front of the queue and returns its value. 
iii. insert (Q, i) — inserts the integer i at the rear of the queue. 
Consider the following function: 

C
 void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
}

What operation is performed by the above function f ?

  • Leaves the queue Q unchanged

  • Reverses the order of the elements in the queue Q

  • Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order

  • Empties the queue Q

Question 27

Consider the C program given below : C
 #include <stdio.h>
int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf (\"%d\\n\", maxsum);

} 
What is the value printed out when this program is executed?
  • 9
  • 8
  • 7
  • 6

Question 28

Consider the following C program: C
   #include 
           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c);
                     else if ((c == \'+\') || (c == \'*\'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == \'+\') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != \' \')
                               flagError ();
             }
              printf(\"% c\", pop ());
}
What is the output of the program for the following input ? 5 2 * 3 3 2 + * +
  • 15
  • 25
  • 30
  • 150

Question 29

Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing. C
 int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{           
    i = 100;
    x = 10;
    y = y + i ;
}
Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
  • Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
  • Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
  • Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
  • Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70

Question 30

Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping. C
 int i ;
program main ()
{
    i = 10;
    call f();
}

procedure f()
{   
    int i = 20;
    call g ();
}
procedure g ()
{   
    print i;
}
Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then, x and y are
  • x = 10, y = 10
  • x = 20, y = 10
  • x = 10, y = 20
  • x = 20, y = 20

There are 80 questions to complete.

Last Updated :
Take a part in the ongoing discussion