Midterm review page for CS241: Data Structures -- Spring 2013

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 ArrayList 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);
                 }
             }  
        }
    
    Add comments that would explain this code to someone unfamiliar with Java. Rename the method to something meaningful.
  29. What is the definition of a binary tree?
  30. Write pseudo-code for a Conway's life simulator
  31. Why must you first count the neighbors of all the Cells and then update them (instead of counting and updating each in order)?
  32. Why must an animation in Java be Threaded?
  33. What does start() do when you send it to a Thread?
  34. Write and AbstractSort class, then two classes that extend it.
  35. Write a Timer class, with a time(AbstractSort) method that times the passed sort on lists of length 1000, 10000, 100000, and 1000000.
  36. Assuming you have timing data for the previous, what patterns would indicate a θ(n2) algorithm vs and θ(n)
  37. Why is it difficult to distinguish θ(n) and θ(nlogn) running times?
  38. What question should have been on this test that wasn't?
  39. And old exam.