Day 0 - Problems

Syllabus Questions

  1. What are you required to do to prepare for each class?
  2. Where can you find the lecture videos, slides, exercises, and problems?
  3. How many missed classes are allowed without making arrangements with Scott?
  4. What is a slip day, how many are you allowed, and how do you use one?

Review Problems

  1. What is printed by the following pseudocode? Reminder: in Java, a Stack’s push method pushes an element onto the stack, while the pop method pops an element off the stack and returns it.

    Stack s = new Stack();
    s.push(8);
    System.out.println(s.pop());
    s.push(10);
    s.push(4);
    System.out.println(s.size());
    System.out.println(s.pop() - s.pop());
  2. What is printed by the following pseudocode? Reminder: in Java, a Queue’s add method enqueues an element, and its remove method dequeues and returns an element.

    Queue q = new Queue();
    q.add(8);
    System.out.println(q.remove());
    q.add(10);
    q.add(4);
    System.out.println(q.size());
    System.out.println(q.remove() - q.remove());
  3. Implement (in java-like pseudocode) the following method:

    /** Reverse the elements of a in-place */
    public static void reverse(int[] a) {
    
      // your code here
    
    }
  4. Implement (in java-like pseudocode) the following method; you may use extra storage, but the end result must be that s contains the same elements but in reverse order:

    /** Reverse the elements of s in-place */
    public static void reverse(Stack s) {
    
      // your code here
    
    }
  5. The Node class below defines a doubly-linked list node:

    public class Node {
      int value;
      Node next;
      Node prev;
    }

    Implement (in java-like pseudocode) the following method:

    /** Reverse the order of the doubly linked list with the given head node. */
    public static void reverse(Node head) {
    
      // your code here
    
    }