Docsity

Midterm Exam for Algorithm Design and Analysis | CSE 202, Exams of Computer Science

Toggle sidebar
bg1
CSE 202 Mid-Term Examination
October 23, 2006
Maximum Points: 25
Time: 80 minutes
Solve ALL THREE problems. In each case, present the main ideas, precise recursive
formulations when called for, and pseudo code for the algorithm along with an appropriate
argument regarding correctness and time complexity.
1. 5 points Suppose the symbols a, b, c, d, and eoccur with frequencies 1/3,1/5,1/7,1/7, and 19/105 respec-
tively.
(a) What is the Huffman encoding of the alphabet?
(b) If this encoding is applied to a file consisting of 1,000,000 chatacters with the given frequencies, what is
the length of the encoded file?
1
pf3

Partial preview of the text

Download Midterm Exam for Algorithm Design and Analysis | CSE 202 and more Exams Computer Science in PDF only on Docsity!

CSE 202 Mid-Term Examination October 23, 2006

Maximum Points: 25 Time: 80 minutes

Solve ALL THREE problems. In each case, present the main ideas, precise recursive

formulations when called for, and pseudo code for the algorithm along with an appropriate

argument regarding correctness and time complexity.

  1. 5 points Suppose the symbols a, b, c, d, and e occur with frequencies 1 / 3 , 1 / 5 , 1 / 7 , 1 / 7 , and 19 / 105 respec- tively.

(a) What is the Huffman encoding of the alphabet? (b) If this encoding is applied to a file consisting of 1,000,000 chatacters with the given frequencies, what is the length of the encoded file?

  1. 10 points A magnetic tape contains n programs of length l 1 , l 2 ,... , ln. We know how often each program is used: a fraction∑ pi of requests to load a program concern program i, 1 ≤ i ≤ n. This of course implies n i=1 pi^ = 1. Information is recorded along the tape at constant density, and the speed of the tape drive is assumed to be a unit constant. Each time a program has been loaded, the tape is rewound to the beginning. If the programs are held in the order σ 1 , σ 2 ,... σn, the average time required to load program σj is Tσj = pσj

∑j k=1 lσk.^ The average time^ T¯ over all programs is T¯ = ∑n i=1 Ti.^ Design an efficient algorithm to determine a placement order (σ 1 , σ 2 ,... , σn) to minimize the average access time T¯. Prove its correctness and analyze its time complexity.