- Use an ArrayList<Foo> to implement a Stack; initialize the ArrayList in the constructor.
- Use an ArrayList<Foo> to implement a Queue.
- Use an array, Foo[], to implement a Stack; initialize the ArrayList in the constructor.
- Use an array, Foo[], to implement a Queue.
- When is an algorithm said to be O(f(n))? Or, what is the definition of O?
- When is an algorithm said to be θ(f(n))? Or, what is the definition of θ?
- Write pseudocode for bubble sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for selection sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for table/counting sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for random sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for oracle sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for radix sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for quick sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Write pseudocode for merge sort. What is its best/worst/average case running time, in θ notation? Explain why.
- Since radix and table/counting sort are so fast, why don't we use them all the time?
- Can any sort be faster than θ(n)? Why?
- What are the two steps in proof by induction?
- What are the two steps in writing a recursive method?
- Prove by induction that 2
^{n}> n^{2}for all n > 5 - Write a recursive int mult(int x, int y) method that returns the product of x and y without using *, / or iteration; no global variables allowed!
- You have two sorts which by your analysis are both θ(n
^{2}); you run a timing experiment and discover that one runs 1000000 times slower than the other. What does this tell you about your analysis? - Write pseudocode to evaluate an arbitrary postfix expression. Assume you are provided with an Emitter (that emits whatever you pass it) and a Tokenizer (that returns the next token whenever you ask for it and which you can ask if it has more tokens).
- Write pseudocode to convert an arbitrary infix expression (without ()'s) to a postfix expression. Again assume I/O is handled as above.
- What must you do to add the ability to handle ()'s to the previous?
- Why is it important to keep your code simple?
- What causes null pointer exceptions? Write code to generate one.
- What are the signatures of the three StringTokenizer constructors? What does each do?
- Pretend you are hired for a programming job and are presented with the following code (from a Conway's Life simulator):

Add comments that would explain this code to someone unfamiliar with Java. Rename the method to something meaningful.`public void paintSomething(Graphics g) { drawGrid(g); for (int up=-1; up<=1; up++) { for (int left=-1; left<=1; left++) { if (up != 0 || left != 0) g.fillRect(LEFT+(specialCol+left)*CELL_WIDTH, TOP+(specialRow+up)*CELL_WIDTH, CELL_WIDTH, CELL_WIDTH); } } }`

- What is the definition of a binary tree?
- Write pseudo-code for a Conway's life simulator
- Why must you first count the neighbors of all the Cells and then update them (instead of counting and updating each in order)?
- Why must an animation in Java be Threaded?
- What does start() do when you send it to a Thread?
- Write and AbstractSort class, then two classes that extend it.
- Write a Timer class, with a time(AbstractSort) method that times the passed sort on lists of length 1000, 10000, 100000, and 1000000.
- Assuming you have timing data for the previous, what patterns would indicate a θ(n
^{2}) algorithm vs and θ(n) - Why is it difficult to distinguish θ(n) and θ(nlogn) running times?
- What question should have been on this test that wasn't?
- And old exam.