GATE-CS-2015 (Set 2)

Last Updated :
Discuss
Comments

Question 1

Consider the C program below. 
 

C
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode)
    {
    case -1:
        size = val;
        break;
    case 0:
        if (stkTop < size ) A[stkTop++]=val;
        break;
    default:
        if (stkTop) return A[--stkTop];
    }
    return -1;
}
int main()
{
    int B[20];
    A=B;
    stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}

The value printed by the above program is ___________
 

  • 9

  • 10

  • 15

  • 17

Question 2

An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is

  • Θ(nlogn)

  • Θ(n)

  • Θ(logn)

  • Θ(1)

Question 3

Suppose you are provided with the following function declaration in the C programming language.

   int partition (int a[], int n); 

The function treats the first element of a[] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part. The following partially given function in the C programming language is used to find the kth smallest element in an array a[ ] of size n using the partition function. We assume k ≤ n

C
int kth_smallest (int a[], int n, int k)
{
   int left_end = partition (a, n);
   if (left_end+1==k)
   {
       return a [left_end];
   }
   if (left_end+1 > k)
   {
      return kth_smallest (____________________);
   }
   else
   {
      return kth_smallest (____________________);
    }
}

The missing argument lists are respectively

  • (a, left_end, k) and (a+left_end+1, n–left_end–1, k–left_end–1)

  • (a, left_end, k) and (a, n–left_end–1, k–left_end–1)

  • (a, left_end+1, N–left_end–1, K–left_end–1) and(a, left_end, k)

  • (a, n–left_end–1, k–left_end–1) and (a, left_end, k)

Question 4

The secant method is used to find the root of an equation f(x) = 0. It is started from two distinct estimates x

a

and x

b

for the root. It is an iterative procedure involving linear interpolation to a root. The iteration stops if f(x

b

) is very small and then x

b

is the solution. The procedure is given below. Observe that there is an expression which is missing and is marked by? Which is the suitable expression that is to be put in place of? So that it follows all steps of the secant method?

Secant

Initialize: xa, xb, ε, N     // ε = convergence indicator
fb = f(xb) i = 0
while (i < N and |fb| > ε) do
i = i + 1 // update counter
xt = ? // missing expression for
// intermediate value
xa = xb // reset xa
xb = xt // reset xb
fb = f(xb) // function value at new xb
end while
if |fb| > ε
then // loop is terminated with i = N
write “Non-convergence”
else
write “return xb
end if
  • xb – (fb– f(xa)) fb/ (xb – xa)

  • xa– (fa– f(xa)) fa/ (xb – xa)

  • xb – (fb – xa) fb/ (xb – fb(xa)

  • xa – (xb – xa) fa/ (fb – f(xa))

Question 5

A Computer system implements 8 kilobyte pages and a 32-bit physical address space. Each page table entry contains a valid bit, a dirty bit three permission bits, and the translation. If the maximum size of the page table of a process is 24 megabytes, the length of the virtual address supported by the system is _______________ bits

  • 36

  • 32

  • 28

  • 40

Question 6

Consider six memory partitions of size 200 KB, 400 KB, 600 KB, 500 KB, 300 KB, and 250 KB, where KB refers to kilobyte. These partitions need to be allotted to four processes of sizes 357 KB, 210 KB, 468 KB and 491 KB in that order. If the best fit algorithm is used, which partitions are NOT allotted to any process?

  • 200 KB and 300 KB

  • 200 KB and 250 KB

  • 250 KB and 300 KB

  • 300 KB and 400 KB

Question 7

Consider the following function written in the C programming language. The output of the above function on input “ABCD EFGH” is

C
void foo (char *a)
{
  if (*a && *a != ` `)
  {
     foo(a+1);
     putchar(*a);
  }
}
  • ABCD EFGH

  • ABCD

  • HGFE DCBA

  • DCBA

Question 8

Given below are some algorithms, and some algorithm design paradigms.

List-I
A. Dijkstra’s Shortest Path
B. Floyd-Warshall algorithm to compute all pairs shortest path
C. Binary search on a sorted array
D. Backtracking search on a graph

List-II
1. Divide and Conquer
2. Dynamic Programming
3. Greedy design
4. Depth-first search
5. Breadth-first search

Match the above algorithms on the left to the corresponding design paradigm they follow Codes:

    A B C D
(a) 1 3 1 5
(b) 3 3 1 5
(c) 3 2 1 4
(d) 3 2 1 5
  • a

  • b

  • c

  • d

Question 9

A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞, and hence there cannot be any entry to the right of, or below a ∞. The following Young tableau consists of unique entries.

1     2     5      14
3 4 6 23
10 12 18 25
31 ∞ ∞ ∞

When an element is removed from a Young tableau, other elements should be moved into its place so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is ____________

  • 2

  • 5

  • 6

  • 18

Question 10

Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the following is consistent with the above statement?

  • Q1 is in NP, Q2 is NP hard

  • Q2 is in NP, Q1 is NP hard

  • Both Q1 and Q2 are in NP

  • Both Q1 and Q2 are in NP hard

Tags:

There are 65 questions to complete.

Take a part in the ongoing discussion