## Midterm review page for CS241: Data Structures -- Spring 2015

The midterm will cover all the material from class and labs.
Some of these questions will appear on the exam.
The exam will have questions not listed below.
1. Use an ArrayList<Foo> to implement a Stack; initialize the ArrayList in the constructor.
2. Use an ArrayList<Foo> to implement a Queue.
3. Use an array, Foo[], to implement a Stack; initialize the array in the constructor.
4. Use an array, Foo[], to implement a Queue.
5. When is an algorithm said to be O(f(n))? Or, what is the definition of O?
6. When is an algorithm said to be θ(f(n))? Or, what is the definition of θ?
7. Write pseudocode for bubble sort. What is its best/worst/average case running time, in θ notation? Explain why.
8. Write pseudocode for selection sort. What is its best/worst/average case running time, in θ notation? Explain why.
9. Write pseudocode for table/counting sort. What is its best/worst/average case running time, in θ notation? Explain why.
10. Write pseudocode for random sort. What is its best/worst/average case running time, in θ notation? Explain why.
11. Write pseudocode for oracle sort. What is its best/worst/average case running time, in θ notation? Explain why.
12. Write pseudocode for radix sort. What is its best/worst/average case running time, in θ notation? Explain why.
13. Write pseudocode for quick sort. What is its best/worst/average case running time, in θ notation? Explain why.
14. Write pseudocode for merge sort. What is its best/worst/average case running time, in θ notation? Explain why.
15. Since radix and table/counting sort are so fast, why don't we use them all the time?
16. Can any sort be faster than θ(n)? Why?
17. What are the two steps in proof by induction?
18. What are the two steps in writing a recursive method?
19. Prove by induction that 2n > n2 for all n > 5
20. 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!
21. You have two sorts which by your analysis are both θ(n2); you run a timing experiment and discover that one runs 1000000 times slower than the other. What does this tell you about your analysis?
22. 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).
23. Write pseudocode to convert an arbitrary infix expression (without ()'s) to a postfix expression. Again assume I/O is handled as above.
24. What must you do to add the ability to handle ()'s to the previous?
25. Why is it important to keep your code simple?
26. What causes null pointer exceptions? Write code to generate one.
27. What are the signatures of the three StringTokenizer constructors? What does each do?
28. Pretend you are hired for a programming job and are presented with the following code (from a Conway's Life simulator):
``````
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);
}
}
}
``````