Problem Set 2
- Suppose there is a program that reads a word and writes the reverse of the word to to output. For example, the program reads "faced" and writes "decaf". The program uses a stack to reverse the string. Please list all activtions of the
push
and pop
methods along with which letter is being pushed or popped at each step if the input word is "rain". (5 pts)
- Show every stack operation and the state of both the
numbers
and operations
stacks after every push and pop when evaluating the arithmetic expression: (((10 * 9) - 3) * (((8 * 2) + 16))). (10 pts)
- What are LIFO and FIFO? (5 pts)
- Given a priority queue, list the order that items would be dequeued given the following set of queue operations. The items in the queue are prioritized by an integer value - higher values have a higher priority. Please show your work. (10 pts)
queue.push("lovelace", 1)
queue.push("knuth", 1)
queue.pop()
queue.push("babbage", 10)
queue.push("church", 7)
queue.push("turing", 8)
queue.pop()
queue.pop()
queue.push("dijkstra", 5)
queue.pop()
queue.pop()
queue.pop()
Org version 7.7 with Emacs version 23
Validate XHTML 1.0