Docsity

Homework Assignment 1 on Algorithm Design and Analysis | CS 410, Assignments of Computer Science

Toggle sidebar
bg1
Homework Assignment #1
CS 410/584 Algorithm Design & Analysis: Spring 2009
This assignment is due Wednesday, 8 April, at the beginning of class. You should work
alone on this assignment. However, you are free to discuss the problems on the class
mailing list or with the TA. (Or you can send us email questions directly; please put โ€œCS
584โ€ at the beginning of the subject line.)
Reading: You should review Chapters 1-14. Topics covered in detail in class correspond
to Section 3.1 (order notation) and Ch. 6 (heapsort). Read Chapter 15 (15.4 is Longest
Common Subsequence).
Office Hours: My office hours are on Tuesday 3:30-5:00p (though I may need to move
the time slightly later depending on my other meetings). Dan Brown, the TA, will have
office hours on Wednesdays 10:30-noon and Fridays 10:30-noon in the Fishbowl by the
CS office.
Note: On any homework exercise where you are asked to give an algorithm, in addition
to describing the algorithm, you must also provide an English description of how it works
and at least one example execution on a non-trivial input.
Exercises: 3.1-4 (10 points); 6.3-1 (10 points; show the heap after each call from build-
max-heap to max-heapify โ€“ see Figure 6.3 as an example); 6.5-7 (15 points); 3-4a, b, d, f
(5 points each).
1A (10 points): This question is about sorting multiple lists. You have k lists, each with n
records in it. The keys for the records are integers in the range 1 to m. (For example, each
list might contain records for students in one department, where the key for each student
record is the number of courses the student has taken.) Give an algorithm to sort all the
lists in total worst-case time of O(kn + m). Note: Sorting each list separately will not give
you the desired time bound.
1B (15 points, 584 students only): Modify the Freq algorithm that I passed out in class so
that it has O(n log(n/f)) worst-case time complexity, where n is the size of collection S
and f is the frequency of the most frequent element (the mode). You may assume a
function Median(S) that returns the middle element of S (in terms of sort order) and runs
in O(n) time. Explain why your algorithm has the claimed time complexity.

Partial preview of the text

Download Homework Assignment 1 on Algorithm Design and Analysis | CS 410 and more Assignments Computer Science in PDF only on Docsity!

Homework Assignment

CS 410/584 Algorithm Design & Analysis: Spring 2009

This assignment is due Wednesday, 8 April, at the beginning of class. You should work alone on this assignment. However, you are free to discuss the problems on the class mailing list or with the TA. (Or you can send us email questions directly; please put โ€œCS 584โ€ at the beginning of the subject line.)

Reading: You should review Chapters 1-14. Topics covered in detail in class correspond to Section 3.1 (order notation) and Ch. 6 (heapsort). Read Chapter 15 (15.4 is Longest Common Subsequence).

Office Hours: My office hours are on Tuesday 3:30-5:00p (though I may need to move the time slightly later depending on my other meetings). Dan Brown, the TA, will have office hours on Wednesdays 10:30-noon and Fridays 10:30-noon in the Fishbowl by the CS office.

Note: On any homework exercise where you are asked to give an algorithm, in addition to describing the algorithm, you must also provide an English description of how it works and at least one example execution on a non-trivial input.

Exercises: 3.1-4 (10 points); 6.3-1 (10 points; show the heap after each call from build- max-heap to max-heapify โ€“ see Figure 6.3 as an example); 6.5-7 (15 points); 3-4a, b, d, f (5 points each).

1A (10 points): This question is about sorting multiple lists. You have k lists, each with n records in it. The keys for the records are integers in the range 1 to m. (For example, each list might contain records for students in one department, where the key for each student record is the number of courses the student has taken.) Give an algorithm to sort all the lists in total worst-case time of O ( kn + m ). Note: Sorting each list separately will not give you the desired time bound.

1B (15 points, 584 students only): Modify the Freq algorithm that I passed out in class so that it has O( n log( n / f )) worst-case time complexity, where n is the size of collection S and f is the frequency of the most frequent element (the mode). You may assume a function Median ( S ) that returns the middle element of S (in terms of sort order) and runs in O( n ) time. Explain why your algorithm has the claimed time complexity.