Sei sulla pagina 1di 2

50 marks

CS 606 Quiz 1

8:30-9:30, 24/1/8

Problem 1: Consider an r c mesh with 1 key per processor. (a)[7 marks] How long will it take
shearsort to run on this mesh? Note that the column sorting step doesnt have to be run fully, (as
discussed in a homework problem). Your answer should exploit this fact. (b)[8
marks] Show that

by choosing r, c carefully, the above algorithm will sort p keys in time O( p log p), rather than

the standard O( p log p).


Column sorting takes r. But because of halving, total time is also O(r). Row
q sorting takes O(c log c)

totally. Thus total time is O(r + c log c). Choosing r = p log p and c = p/ log p we get the time
to be as required.
Problem 2:(a)[10 marks] Priority queue with a delete instruction: Design a linear array that
can take as input commands Insert(x), Delete-min, and Delete(x) which should respectively
insert the specified element, return the smallest element currently in the array after deleting it,
and delete the specified element from the array if it exists. In other words, this is the same as
the homework problem, except for the extra Delete(x) instruction. The Delete(x) instruction
is expected to delete just one copy of x if many are present. The array should be of the same size
as the number of elements as can be in present at any time. As there, the response to Delete-Min
should arrive in the next step.
Show the final systolic design (assuming you used systolic conversion). Explain your design. For
example, you may say: In this semi-systolic design, at the end of the ith step the following
invariants will hold. Must state the invariant(s) very clearly. No invariants are expected for the
final systolic design.
The array has zero delay edges going away from the host. The command is broadcast on it. Each node
holds a key. The keys are in increasing order. At the end of each step, each node either has a key or
is about to receive one from its right neighbour.
Action of a node receiving delete-min: send its key left. Send delete-min to the right.
Action of a node receiving insert(x): compare to its key, keep smaller and send insert(larger) to the
right.
Action of a node receiving delete(x) : compare x with its key. If there is a match, then send delete-min
to right. Else send delete(x) to right.
(b)[10 marks] Suppose the Delete(x) instruction is expected to delete all copies. What changes
are needed explain briefly.
Keep a counter with each key. When an insert instruction is received, increment the current key if it
is x and pass a no-op to the right. If current key is smaller, then send insert(x) to right. If current key
is larger, then create a place in the current processor with count =1, and send the current processors
key/count to left to be inserted. On delete-min, send noop to right if the current count is greater than
1 after decrementing the count. If the current count is zero, then send shift to right.
Note: the solution to part (a) cannot be extended. Suppose the smallest key has several copies. You
can mark all deleted in one semisystolic step, however, a following delete-min instruction cannot be

satisfied in one step, since the leading processors will have no keys.
Problem 3:[15 marks] Consider a 2n leaf complete binary tree in which leaf i holds a numerical
value xi . Your goal is to produce at each node a value yi which must equal xj where j is the largest
integer equal to or less than i such that xj 6= 0. Thus if the input is the sequence 1,2,0,0,1,0,5,0
then the output should be 1,2,2,2,1,1,5,5. Show how this can be done in O(n) time.
Define x+y=x if y is 0, and y otherwise. a+b+c=c for non-zero a,b,c. 0+a+b=b, a+0+b=b,
a+b+0=b, 0+0+a=a, 0+a+0=a, a+0+0=a, 0+0+0=0 no matter in what order the operators are
evaluated.
Note: You may have given a correct algorithm and yet lost marks if you didnt give a proper explanation.
At least you should state (not formally) prove what properies you expect on the value being transmitted
on a link, e.g. the value coming from the parent will be 0 if all keys to right of subtree are 0, else it
will be the rightmost nonzero value.

Potrebbero piacerti anche