GATE CS 1996

Last Updated :
Discuss
Comments

Question 1

The process state transition diagram in below figure is representative of Untitled                

  • a batch operating system
  • an operating system with a preemptive schedular
  • an operating system with a non-preemptive schedular
  • a uni-programmed operating system

Question 2

Quicksort is run on two inputs shown below to sort in ascending order taking the first element as pivot,

(i) 1, 2, 3,......., n
(ii) n, n-1, n-2,......, 2, 1 

Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then,

  • C1 < C2 
     

  • C1 > C2

  • C1 = C2

  • We cannot say anything for arbitrary n

Question 3

Which of the following is false? opt1              

  • a
  • b
  • c
  • d

Question 4

A two dimensional array A[1...n][1...n] of integers is partially sorted if
i, j ∈ [1...n−1], A[i][j] < A[i][j+1] and A[i][j] < A[i+1][j]
Fill in the blanks: a) The smallest item in the array is at A[i][j] where i=..................and j=...................... b) The smallest item is deleted. Complete the following O(n) procedure to insert item x (which is guaranteed to be smaller than any item in the last row or column) still keeping A partially sorted.
procedure insert (x: integer);
var i,j: integer;
begin
    i:=1; j:=1, A[i][j]:=x;
    while (x > ...... or x > ......) do
        if A[i+1][j] < A[i][j] ......... then begin
            A[i][j]:=A[i+1][j]; i:=i+1;
        end
        else begin
            ............
        end
    A[i][j]:= .............
end
.

    Question 5

    A complete, undirected, weighted graph G is given on the vertex {0, 1,...., n−1} for any fixed ‘n’. Draw the minimum spanning tree of G if a) the weight of the edge (u,v) is ∣ u−v ∣ b) the weight of the edge (u,v) is u + v

      Question 6

      Consider the following program that attempts to locate an element x in a sorted array a[ ] using binary search. Assume N>1. The program is erroneous. Under what conditions does the program fail?

      C++
      #include <iostream>
      #include <vector>
      using namespace std;
      
      int find(vector<int>a, int n) {
          int i = 1, j = n;
          int x;
          do {
              int k = (i + j) / 2;
              if (a[k] < x) i = k + 1;
              else j = k;
          } while (a[k] != x && i < j);
          
          if (a[k] == x)
              cout << "x is in the array" << endl;
          else
              cout << "x is not in the array" << endl;
          return 0;
      }
      
      C
      #include <stdio.h>
      #include <stdbool.h>
      
      int find(int a[], int n, int x) {
          int i = 1, j = n;
          int k;
          do {
              k = (i + j) / 2;
              if (a[k] < x) i = k + 1;
              else j = k;
          } while (a[k] != x && i < j);
          
          if (a[k] == x)
              printf("x is in the array\n");
          else
              printf("x is not in the array\n");
          return 0;
      }
      
      Java
      import java.util.List;
      
      public class Main {
          public static void find(int arr[], int n, int x) {
              int i = 0, j = n;
              int k;
              do {
                  k = (i + j) / 2;
                  if (arr[k] < x) i = k + 1;
                  else j = k;
              } while (i < j && arr[k] != x);
      
              if (arr[k] == x)
                  System.out.println("x is in the array");
              else
                  System.out.println("x is not in the array");
          }
      }
      
      Python
      def find(a, n, x):
          i = 0
          j = n
          while i < j:
              k = (i + j) // 2
              if a[k] < x:
                  i = k + 1
              else:
                  j = k
          
          if i < len(a) and a[i] == x:
              print("x is in the array")
          else:
              print("x is not in the array")
      
      JavaScript
      function find(a, n, x) {
          let i = 0, j = n;
          let k;
          do {
              k = Math.floor((i + j) / 2);
              if (a[k] < x) i = k + 1;
              else j = k;
          } while (a[k] !== x && i < j);
          
          if (a[k] === x)
              console.log("x is in the array");
          else
              console.log("x is not in the array");
      }
      


      • x is the last element of the array a[]

      • x is greater than all elements of the array a[]

      • Both of the Above

      • x is less than the last element of the array a[]

      Question 7

      Let G be the directed, weighted graph shown in below figure gra We are interested in the shortest paths from A. (a) Output the sequence of vertices identified by the Dijkstra’s algorithm for single source shortest path when the algorithm is started at node A. (b) Write down sequence of vertices in the shortest path from A to E. (c) What is the cost of the shortest path from A to E?

        Question 8

        A demand paged virtual memory system uses 16 bit virtual address, page size of 256 bytes, and has 1 Kbyte of main memory. LRU page replacement is implemented using a list whose current status (page number in decimal) is pagetab       . For each hexadecimal address in the address sequence given below
         00FF, 010D, 10FF, 11B0
        indicate i) the new status of the list ii) page faults, if any, and iii) page replacements, if any

          Question 9

          A 1000 Kbyte memory is managed using variable partitions but no compaction. It currently has two partitions of sizes 200 Kbytes and 260 Kbytes respectively. The smallest allocation request in Kbytes that could be denied is for
          • 151
          • 181
          • 231
          • 541

          Question 10

          Consider the following program in pseudo-pascal syntax. What is printed by the program if parameter in procedure test1 is passed as i) call-by-reference parameter ii) call-by-value-result parameter
          program Example (input, output)
          var b: integer;
          procedure test2:
          begin b:=10; end
          procedure test1 (a:integer):
          begin 	a:=5;
                  writeln ('point 1: ', a, b);
                  test2;
                  writeln ('point 2: ', a, b);
          end
          begin (*Example*)
          b:=3; test1(b);
          writeln('point3: ', b);
          end
          
            Tags:

            There are 75 questions to complete.

            Take a part in the ongoing discussion