Bard College – Computer Science – Data Structures
We’ll practice the experimental approach for evaluating algorithms outlined in section 1.4(pg 174–179).
ThreeSum
First, develop run-time models T(N) of ThreeSum and ThreeSumFast on your own machine.
Gather run-time statistics for both programs using varying input sizes(e.g.1K, 2K, 4K, 8K, 16K) using StopWatch.(Best to record the means of many experiments per input size; why?)
Enter those findings into a spreadsheet.
Plot the running time of both algorithms(a scatter-plot with standard axes and a trend line).
Log-transform the data.
Plot the log-transformed data and compute the best-fit line(i.e., linear trend-line).
You can use the =SLOPE(D2:D16, C2:C16) and =INTERCEPT(D2:D16, C2:C16) formulas for finding the equation of the best-fit line.
Report your estimate of T(N)=aNm and use it to predict the run-times of the various input sizes.
Reflect on how well your model summarizes and predicts run-times.
Traveling Salesperson
Second, develop run-time models for the two heuristics for finding Traveling Salesperson tours we developed last week; follow the same process as you did with ThreeSum . If you were unable to get both heuristics working yet, use the reversing task in its place(see below).
Submission
Submit a PDF file describing your findings: include the graphs, tables of the data, and the resulting mathematical models.
EXTRA: Reversing a Stream
Compare the performance of array-based data structures to reverse a stream of data. Compare the book’s strategy(doubling the size of the array) with the naive approach where you grow and shrink the array by one.
ResizingArrayStack<Integer> stack = new ResizingArrayStack<Integer>();
Develop models for both types of array-based data structures. You will have to modify the book’s ResizingArrayQueue& ResizingArrayStack to grow and shrink by 1.
EXTRA; EXTRA: You might also compare with the linked-list variety: Queue and Stack .
Lab 5 Checklist
Did I evaluate both algorithms?
Did I use the specified varying input sizes?
Does my report include graphics such as graphs, tables, and mathematical models?
ThreeSum
Traveling Salesperson
Submission
EXTRA: Reversing a Stream
ResizingArrayStack<Integer> stack = new ResizingArrayStack<Integer>();
while (!q.isEmpty()) stack.push(q.dequeue());
while (!stack.isEmpty()) q.enqueue(stack.pop());
Lab 5 Checklist