GATE CS 1996 (original) (raw)

The process state transition diagram in below figure is representative ofUntitled

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,

Which of the following is false?opt1

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 .

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

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 #include using namespace std;

int find(vectora, 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");

}

`

Let G be the directed, weighted graph shown in below figuregraWe 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?

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) ispagetab. 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

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

Consider the following program in pseudo-pascal syntax. What is printed by the program if parameter a 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

There are 75 questions to complete.

Take a part in the ongoing discussion