CSC252a
Fall 2000
Ileana Streinu

Homework 1

Tuesday, Sept. 12, 2000
Due: Tuesday, Sept. 19, 2000 - before class


Programming

The goal is to write a program to compare the running times of two functions. In our case, these two functions are Sequential Search and Binary Search, which can be implemented by following the pseudocode description presented in class. The main program will generate input values for the search programs: a list L of size n to be searched and a value x to be looked for in L. Then will call each function in turn, compute the time it ran, and store it. Iterate this on several values of n, L and x, store the results in an array and print them. I recommend that you generate lists of size n = 2, 4, 8, 16, ... (powers of 2) which consist of the first n integers in sorted order (1,2, .. , n), and random values for the search variable x, using the random number generator. For extra credit, find the value of n when your programs seem to break even.

How to find the time:

I wrote a little program that will serve as a template for this assignment. You can find it here. My program uses two functions, one running in quadratic time, the other in cubic time. It gets the time each function spent running, and prints them.
You can simply substitute your code for the two search functions, together with appropriate code for generating input for them. You might have to calibrate the values of n to get meaningful results.

How to submit

Use submit Hw1 filename from your class account to submit the program. In class, bring a printed copy of the program and a printed output from your program (typescript). Use script for this: ask one of your colleagues or me, if you do not know how to use script. On the typescript, in legible handwritting, please give me some information about your program: does it compile? execute? does it run correctly, from all you can see? do the running times seem reasonable? Make sure your name and class account is on the printout. Comment generously.

Big Oh

For the following pairs of functions, tell whether one is Big Oh or little Oh of the other. Justify your answer by providing the appropriate limit calculation.
1. 3n^2 - 4000 n +2 and 2 n + 100 log n
2. 3n^2 - 4000 n +2 and 2 n log n + 20 n - 14
3. 2^n + n^5 and 3^n + n + 2
4. n/(log n) and log n
5. n^3/(n log n + n^2) and (n + log n)/(log n + (log n)^2)
6. n + log n and (log n)^2

Last modified Sept. 12, 2000.