Question 1
The process state transition diagram in below figure is representative of
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?
Question 4
∀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?
#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;
}
#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;
}
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");
}
}
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")
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
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
.
For each hexadecimal address in the address sequence given below
00FF, 010D, 10FF, 11B0indicate i) the new status of the list ii) page faults, if any, and iii) page replacements, if any
Question 9
Question 10
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.