Homework Assignment 1


Due: Jan. 19 before class starts


Assignment

  1. (30 points) Give a recursive method for removing all the elements from a stack.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  2. (30 points) Postfix notation is an unambiguous way of writing an arithmetic expression without parenthesis. It is defined so that if (exp1) op (exp2) is a normal fully parenthesized expression whose operation is op, the postfix notation is pexp1 pexp2 op, where pexp1 is the postfix version of exp1 and pexp2 is the postfix version of exp2. So, for example, the postfix version of ((5+2)*(8-3))/4 is 5 2 + 8 3 - * 4 /. Describe a nonrecursive way of evaluating an expression in postfix notation.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  3. (40 points) Describe how to implement the four update methods of the deque ADT using two stacks as the only instance variables of the deque.
    1. Provide and explain pseudocode for each method
    2. Statement and proof of time complexity for each method
    3. Statement and proof of memory complexity for each method
  4. Bonus. (10 points) Suppose you have a stack S containing n elements and a queue Q that is initially empty. Describe how you can use Q to scan S to see if it contains a certain element x, with the additional constraint that your algorithm must return the elements back to S in their original order. You may only use S, Q, and a constant number of other primitive variables.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity


General Instructions, Turning in assignments, and Grading

General Instructions

Turn in Instructions

Each assignment will be turned in in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean five minutes after class starts. Details:

Points