Homework Assignment 2


Assignment

  1. (50 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. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  2. (50 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. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  3. 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. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.


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 one minute after class starts. Details:

Grading