CS 1723-001 Data Structures
Fall 2001 -- Answers to Mid-Term Exam
  1. Here are two separate questions related to RPN (Reverse Polish Notation):

    1. Consider the following arithmetic expression:
            3^2*(4-2)+6
         
      1. In translating this arithmetic expression to RPN, what kinds of items are pushed on a stack?

        Operators and parentheses are pushed on the stack as wrapped chars. In the example here, pushed will be: ^ * ( - ) +.

      2. Give the RPN that corresponds to this expression.

        Here is the RPN: 32^42-*6+

    2. Consider the following arithmetic expression in RPN form (not the same as the answer to part (a) above):
            34*23^8+/
         
      Use the technique that was presented in class to evaluate the resulting RPN, showing step-by-step the use of a stack.

      Actions: push 3; push 4; pop 4 and 3, push 3*4 = 12; push 2; push 3; pop 3 and 2, push 2^3 = 8; push 8; pop 8 and 8, push 16; pop 16 and 12, push 12/16 = 0.75.


  2. Here is one version of the program. Output is:
    
    2 3 5 7 11 13 17 19 23 0
    23
    19
    17
    13
    11
    7
    5
    3
    2
    

  3. Here is the complete answer to problem 3:
Points for each problem: 1-20, 2-30, 3-50.