Docsity

Assignment 4 - Algorithm Design and Analysis | ECS 122A, Assignments of Computer Science

Toggle sidebar
bg1
ECS122A: Algorithm Design and Analysis Due: 5:00pm, May 7, 2009
Homework Assignment #4
1. Do Exercise 16.1-3
2. We are given njobs j1, j2,...,jn, with known running time t1, t2, . . . , tn, respectively. We have a
single processor. We want to schedule these jobs so as to minimize the avarage completion time?
We assume nonpreemptive scheduling, i.e., once a job is started, it must run to completion.
Specify a greedy algorithm for the job scheduling problem, and prove the optimality.
3. The 0-1 knapsack problem. Six items {(i, vi, wi)}(viand wiare the value and weight of item i,
resp.) are given as follows:
i viwi
1 40 100
2 35 50
3 18 45
4 4 20
5 10 10
6 2 5
The total weight W= 100.
(a) Find the greedy solutions by using following possibilities:
(i) Greedy by value, i.e., at each step select from the remaining items the one with the
highest value
(ii) Greedy by weight, i.e., at each step select from the remainin g items the one with the
least weight.
(iii) Greedy by the value per pound, i.e., at each step select from the remaining items with
the largest ratio vi/wi.
(b) Compute the solution by dynamic programming (attach a copy of your program)
(c) Briefly comment your findings.
4. Give a Huffman code for the following string:
ACCGGTCGAGTGCGCGGAAGCCGGCCGAA
describe both your tree and the actual binary encoding.
5. Do Exercise 16.3-2
1

Partial preview of the text

Download Assignment 4 - Algorithm Design and Analysis | ECS 122A and more Assignments Computer Science in PDF only on Docsity!

ECS122A: Algorithm Design and Analysis Due: 5:00pm, May 7, 2009 Homework Assignment #

  1. Do Exercise 16.1-
  2. We are given n jobs j 1 , j 2 ,... , jn, with known running time t 1 , t 2 ,... , tn, respectively. We have a single processor. We want to schedule these jobs so as to minimize the avarage completion time? We assume nonpreemptive scheduling, i.e., once a job is started, it must run to completion. Specify a greedy algorithm for the job scheduling problem, and prove the optimality.
  3. The 0-1 knapsack problem. Six items {(i, vi, wi)} (vi and wi are the value and weight of item i, resp.) are given as follows:

i vi wi 1 40 100 2 35 50 3 18 45 4 4 20 5 10 10 6 2 5

The total weight W = 100.

(a) Find the greedy solutions by using following possibilities: (i) Greedy by value, i.e., at each step select from the remaining items the one with the highest value (ii) Greedy by weight, i.e., at each step select from the remainin g items the one with the least weight. (iii) Greedy by the value per pound, i.e., at each step select from the remaining items with the largest ratio vi/wi. (b) Compute the solution by dynamic programming (attach a copy of your program) (c) Briefly comment your findings.

  1. Give a Huffman code for the following string:

ACCGGTCGAGTGCGCGGAAGCCGGCCGAA

describe both your tree and the actual binary encoding.

  1. Do Exercise 16.3-