CSc 150
Preparing for the Final

To help you study, here's a quick list of the major topics for the final. The exam is open book, open notes, and will have the same format as the midterm. Remember to bring your text with you to the exam since no sharing of books will be allowed. This list is NOT meant to be complete (everything we covered in lecture and in the text is fair game) but it'll help you start studying. As a reminder, I'm testing your ability to problem-solve, not regurgitate definitions and the like. So while there will be standard test-like things such as true/false, multiple choice, etc., the bulk will revolve around you understanding concepts, applying them to new situations, writing code, and knowing the difference between well-designed and poorly-designed programs. It is still important that you KNOW all the terms we've been using in class so you understand the exam questions correctly.

Java and Object-Oriented Programming (OOP)

Good Program Design (OO goals)

Time Complexity

ADTs

Recursion

Searching

Review Questions

  1. Write a method called binSearch() that performs a recursive binary search on an array of ints. The prototype will be:

    public int binSearch(int[] A, int key)
    
    where A is a sorted array of ints and key is what you are searching for.

    Your method will return the index of the found key or -1 if the key was not found.

    You should be able to solve this with just the above, but if you get stuck, here's a hint to help you.

  2. Suppose you wrote a Stack class with the following methods:
    public void push(String x)
    public String pop()
    public String top()
    public int size()
    public boolean isEmpty()
    
    and a Queue class with the following methods:
    public void insert(Object x)
    public Object remove()
    public int size()
    public boolean isEmpty()
    

    Write the following method in the Stack class:

    public void reverse()
    

    that reverses the elements in the stack. So whatever was at the top of the stack will now be at the bottom. This method is destructive by nature. You must write your code using only the behavior indicated above, without relying on any specific implementation. You may assume that default constructors exist in both classes.

  3. Which of the following are heaps? For those that are not, why not?

  4. Assume we have the following LinkedList and ListNode classes:
    public class LinkedList                 public class ListNode
    {                                       {
       private ListNode firstNode;              public int data;
       private int length;                      public ListNode next;
    
       public LinkedList {                      public ListNode {
         firstNode = null;                        data = null;
         length = 0;                              next = null;
       }                                        }
    }                                       }
    
    Suppose this represented a circular linked list (where the last node points back to the first node). Write the following method in the LinkedList class:
    public void linearize()
    
    which turns the circular linked list back into a linear one (where the last node points to null). Remember, in a 1-node circular list, the node points back to itself.

  5. In a BinarySearchTree class, write the following recursive method:
    public int leafCount()
    
    which returns the number of leaves in the tree. You may assume the existence of the standard BSTnode class that we've seen before.

  6. Using h(k)=k%M as a hash function, show the final state of the hash table after the following keys have been inserted:

    62, 73, 19, 32, 66, 54

    Use linear probing to resolve collisions where the probe will move toward higher indices in the table. The table size, M, is 11.

  7. Redo the problem above except use double hashing to resolve collisions. p(k)=max(1,(k/M)%M)

  8. Draw the expression tree for a*((b+c)*(d*e+f)). Then draw the expression tree for a*(b+c)*(d*e+f). Why are they different?

  9. Insert the following values into a maxheap. After each insertion, show the state of the heap in both tree form and array form.

    44, 66, 33, 88, 77, 55, 22.


CSc 150 homepage