|CSC 301||Grinnell College||Fall, 2011|
|Analysis of Algorithms|
|Quick Links: September October November December|
The accompanying table indicates assignments and due dates for Computer Science 301 and are subject to the following notes.
Unless otherwise indicated, textbook references are to Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein, Introduction to Algorithms, Third Edition, Cambridge, Massachusetts: The MIT Press, 2009; ISBN 978-0-262-00384-8.
Supplemental problems are stated later on this page.
Since collaboration is allowed on some assignments, but not on others, the following table clarifies the rules for collaboration for each assignment.
When turning in problems from the text, the solutions must be given in problem order. That is, if problem A has an exercise number lower than problem B, then the solution to problem A must be given before the solution to problem B.
|Fri., Sept. 2||3-4|
|Wed., Sept. 7||3-4 revisions|
|Fri., Sept. 9||Choose 3 of 4.2-1 to 4.3-6|
|Wed., Sept. 14||5.1-2 (can assume the number of integers in [a, b] is a power of 2), 5.1-3, 5.2-1, one of (5.2-2, 5.2-3, 5.2-4)|
|Mon., Sept. 19||6.5-7, 6.5-9, 7.4-5|
|Wed., Sept. 21||8.4-1, 8.4-2, 8-2|
|Fri., Sept. 23||Hour Test 1|
|Wed., Sept. 28||supplemental problem 1|
|Wed., Oct. 5||11.3-1, 11.4-1, two of (11.2-1 through 11.2-6)|
|Mon., Oct. 10||Lab on Pictorial Loop Invariants||Reading on Pictorial Loop Invariants|
|Wed., Oct. 12||supplemental problem 2||Solutions with identical PQ.java, PQImplementation.java (Also, PQItem.java identical for array and LinkedList versions)|
|Wed., Oct. 26||supplemental problems 3, 4|
|Wed., November 9||Take Home Test due|
|Fri., November 18||2 of (22.1-4, 22.1-5, 22.1-6); 2 of (22.4-2, 22.3-4, 22.2-7)|
|Wed., November 23||supplemental problem 5|
|Mon, December 5||Take Home Test due|
Comparison of Sorting Algorithms
In this lab, you are to compare the performance of five sorting algorithms, including:
In developing the comparison, you will need to code each algorithm in the same programming language (possible choices are Scheme, C, or Java), and you will need to run all algorithms on the same data sets of varying sizes. Here are some details.
Try to code each algorithm in a similar style, in order to minimize the impact of idiosyncrasies of coding.
Your tests should generate three data sets for files of size 10,000, 20,000, 40,000, 80,000, ... . One data set should be ordered in ascending order, one data set should contain random data, and one data set should be in descending order.
Each data set is to contain only positive integers, the numbers may have up to 8 decimal digits (a size is needed for the radix sort), and each data set is to be sorted in ascending order by each algorithm.
Your program should determine the time spent by the sorting algorithm separately for each data set. The timing should NOT include any set up before the sorting algorithm (e.g., not array initialization), and the timing should NOT include any clean up at the end (e.g., memory deallocation, printing). However, the timing should include any required initialization of variables required for the algorithm.
Since processor speeds, machine capabilities, and run-time environments will vary by language, the program should continue testing algorithms with data sets that progressively double in size until some algorithm requires over 10 seconds to finish on one data set.
The program should produce a table of times in the following format:
Data Set Times Algorithm Size Ascending Order Random Order Descending Order Insertion sort 10000 Merge sort 10000 Heap sort 10000 Quicksort 10000 Radix sort 10000 Insertion sort 20000 Merge sort 20000 Heap sort 20000 Quicksort 20000 Radix sort 20000 ...
Once you have the times collected for the various algorithms, plot the times versus the data set size using any graphing software you wish. (A spreadsheet might be used, but you also might use MatLab, Maple, or other package.) For each algorithm, the times for the three data sets should be connected (that is, one line would connect the times for the insertion sort with ascending data against sizes 10000, 20000, 40000, ... .)
If the graphing software allows, it would be helpful to have the graphs for all algorithms with ascending order combined on one plot, the graphs for all algorithms with random data on a second plot, and the graphs for all algorithms with descending data on a third plot. In addition, a graph of a line (f(n)=n) and a quadratic (f(n) = n^2) would be helpful (but not required).
K-way Merge with Priority Queue/Heap
Exercise 6.5-9 in Cormen et al asks for the development of a K-way merge of sorted lists, using a min-heap (or priority queue). This problem asks you to write a Java program to implement this algorithm. In particular,
To ensure encapsulation of the heap/priority queue, your K-way merge must provide an implementation of the abstract class PQ.java.
Elements inserted into the min-heap (or priority queue) must be elements of
class PQItem that implements Java's
interface. That is, the header for PQItem should be
public class PQItem implements Comparable<PQItem>
Priority of elements in PQ.java are determined by
compareTo method within class PQItem, where
item1 is given higher priority than
item1.compareTo(item2) < 0.
Your K-way merge may begin with sorted data in either K lists or K arrays. The program should not require that these lists or arrays have the same length.
Your K-way merge should produce sorted data in a single list or array, consistent with the type of the inputs. For example, if your beginning sorted data come from lists, then the resulting data should also be in a list.
Red-Black Tree Insertion: (Patterned after Cormen et al, 13.3-2) Show the red-black tree that results after successively inserting the keys 50, 75, 85, 25, 10, 20, 15, 0 into a tree that was initially null.
Red-Black Tree Deletionion: Consider the following Red-Black Tree:
Show the red-black tree that results after successively deleting the keys 5, 26, 38, 40, 56, 80, 90, 50.
Graphs: Consider the weighted, directed graph with:
|Edges:||<A,I>: 2||<B,A>: 3||<B,I>: 4||<C,B>: 2||<D,C>: 3||<D,E>: 4||<D,G>: 8|
|<E,F>: 2||<F,G>: 3||<F,L>: 3||<G,H>: 2||<G,K>: 4||<H,J>: 5||<I,H>: 3||<L,D>: 1|
When considered as a directed, weighted graph, this gives the following diagram
In several of the following exercises, the relevant algorithm sometimes allows choices of vertices or edges that meet certain criteria. Whenever there is a choice of vertices, choose the one that comes first in alphabetical order. Whenever there is a choice of edges, choose the edge with initial vertex coming first in alphabetical order; if two edges have the same initial vertex in alphabeticqal order, choose the edge with final vertex coming first in alphabetical order.
This document is available on the World Wide Web as
created 17 August 2011
last revised 22 October 2011
|For more information, please contact Henry M. Walker at email@example.com.|