Question 1
Shared Data mutex:semaphore = 1:/* initialized to 1*/ process[3]:semaphore = 0; /*all initialized to 0 */ R_requested [3]:boolean = false; /*all initialized to false */ busy: boolean = false; /*initialized to false */
Code for processes
begin process
my-priority:integer;
my-priority:=____; /*in the range 1...3*/
repeat
request_R(my-priority);
P (proceed [my-priority]);
{use shared resource R}
release_R (my-priority);
forever
end process;
Procedures
procedure request_R(priority);
P(mutex);
if busy = true then
R_requested [priority]:=true;
else
begin
V(proceed [priority]);
busy:=true;
end
V(mutex);
Give the pseudo code for the procedure release_R.Question 2
A priority queue Q is used to implement a stack S that stores characters. PUSH(C) is implemented as INSERT(Q, C, K) where K is an appropriate integer key chosen by the implementation. POP is implemented as DELETEMIN(Q). For a sequence of operations, the keys chosen are in
Non-increasing order
Non-decreasing order
strictly increasing order
strictly decreasing order
Question 3
[5-Marks question]
Consider a graph whose vertices are points in the plane with integer co-ordinates (x,y) such that 1≤x≤n and 1≤y≤n, where n≥2 is an integer. Two vertices (x1,y1) and (x2,y2) are adjacent iff ∣ x1−x2 ∣ ≤ 1 and ∣ y1–y2 ∣ ≤1. The weight of an edge {(x1,y1),(x2,y2)} is √(x1–x2)2+(y1–y2)2
a. What is the weight of a minimum weight-spanning tree in this graph? Write only the answer without any explanations.
b. What is the weight of a maximum weight-spanning tree in this graph? Write only the answer without any explanations.
Question 4
(A) All pairs shortest path (1) Greedy (B) Quick Sort (2) Depth-First search (C) Minimum weight spanning tree (3) Dynamic Programming (D) Connected Components (4) Divide and and Conquer
Codes:
A B C D
a 2 4 1 3
b 3 4 1 2
c 3 4 2 1
d 4 1 2 3
Question 5
An array A contains n≥1 positive integers in the locations A[1], A[2],... A[n]. The following program fragment prints the length of a shortest sequence of consecutive elements of A, A[i], A[i+1],...A[j] such that the sum of their values is ≥M, a given positive number. It prints ‘n+1’ if no such sequence exists. Complete the program by filling in the boxes. In each case use the simplest possible expression. Write only the line number and the contents of the box.

Question 6
Question 7
Question 8
Question 9
type list = record next:↑ list; val: integer endThe following function returns a list in which a2i and a2i-1, 1 ≤ i ≤ [n/2] are interchanged. Complete the function by filling the boxes. Write the line number and the content of the box in your answer sheet.
Question 10
program what:
var z: integer
procedure recur(x):
begin if x <= 40 then
begin x:x+z
recur(x);
z:=x+10
end
end(*recur*)
begin(*what*)
z=10;
recur(z);
writeln(z)
end
a. Suppose the parameter to the procedure ‘recur’ is passed by value.
i. What value is printed by program?
ii. How many times is ‘recur’ called?
b. What value is printed by the program if the parameter is passed by reference?There are 75 questions to complete.