HW 6
HW 6
, tn for execution by a
single processor. The jobs can be executed in any order, one job at a time. You want to find a schedule
that minimizes the total time spent by all the jobs in the system. (The time spent by one job in the system
is the sum of the time spent by the job in waiting plus the time spent on its execution.)
Answer: sort all jobs in increasing order by execution time. Execute each job starting with the
smallest one (thus we minimize waiting time for the next following job). Take as waiting time for
the next job execution time of the previous job. Sum = sum + execution + waiting time for each
job.
(b) Does your algorithm always provide an optimal solution? (Yes/No). If your answer is “No”,
present a counterexample.
Answer: Yes
4. (10 points) This is about the Coin-Row problem. Assume that there are six coins like below
5, 4, 1, 8, 10, 6
Fill out the table using dynamic programming method as discussed in the class After that, present the set
of coins to be picked and maximum amount. Do you have only one optimal solution?
Index 0 1 2 3 4 5 6
Ci N/a 5 4 1 8 10 6
F(i) 0 5 5 6 13 16 19
Answer: Set of coins{5, 8, 6}. Max amount = 19. Yes, one optimal solution.
5. (10 points) Assume that you have the following directed graph. Find the transitive closure of the graph
using the algorithm covered in the class. In other words, you have to present R(0), R(1), R(2), R(3), R(4), and
R(5) to solve the problem. For your understanding, R(0) is presented below as an example. Thus, you should
present the R(1), R(2), R(3), R(4), and R(5).
R(0)
1 2 3 4 5
1 0 1 1 0 0
2 0 0 0 1 1
3 0 0 0 0 1
4 0 1 0 0 1
5 1 0 0 0 0
Page 2 of 5
6. (5 points) Find the minimum spanning tree (MST) to the following graph using the Prim’s algorithm as
you learned in the class. For the problem, you have to start the algorithm from the vertex I. Then, present
the sequence of vertices/edges to be added, indicate the weights for the edges, and draw the result MST
clearly.
Page 3 of 5
Answer:
vertices = { I, A, F, G, H, B, C, E, D}
weights = { 4, 5, 1, 7, 3, 2, 9, 14}
Page 4 of 5
Page 5 of 5