Special Note: Do not use any other functions or a counter (NO CREDIT will be assigned).
Semaphore A = _____; // initialization of semaphore, should be some integer value
Semaphore B = _____;
Semaphore C = _____;
P0: P1:
while (true) { while (true) {
1: 4:
2: 5:
3: 6:
} }
|
|||||||||
|
a) Based on the Gantt chart, fill-in the code such that each process has three semaphore calls.
b) Based on the Gantt chart and code, fill-in the initialization of the semaphores, that is,
the initial value of the integer counter.
int a[2];
void z(int b[], int i, int j) {
int k;
a[0] = 2;
k = b[i];
b[i] = b[j];
b[j] = k;
i = j;
print(a[0], a[1], i, j);
}
main() {
int i = 0; int j = 1;
a[0] = 2;
a[1] = 3;
z(a, i, j);
print(a[0],a[1], i, j);
}
For each of the following parameter mechanisms, briefly describe the mechanism, and show the output from the program.
a) call by value (for all types, including arrays)
b) call by reference
c) call by value-result
//START CODE
for (int i = 1; i < n; i++) { //OUTER LOOP ONE
Perform 2 fundamental operations;
for (j = i+1; j <= n; j++) //INNER LOOP
Perform 3 fundamental operations;
//endfor
}//endfor
for (int k = n; k > 0; k = k/2) //OUTER LOOP TWO
Perform 1 fundamental operation;
//endfor
//END CODE
a) Show - carefully and completely - that VERTEX COVER is in NP.
b) Suppose that you are told that EDGE COVER is in P, and also that
EDGE COVER is polynomially reducible to VERTEX COVER,
EDGE COVER ≤P VERTEX COVER. What does this tell you about VERTEX COVER? Why?