int stackLength(Stack stack)
, that returns the number of items on the stack and that runs in constant time.
void * itemAtPosition(list L, int P)
, that returns the item stored at the link at position P in list L (as always, we consider that the first link in the list is at position 0).
A letter means push and an asterisk means pop in the sequence:
E A S * Y * Q U E * * * S T * * * I O * N * * *.Give the sequence of values returned by the pop operations.
Given two sequences, give an algorithm for determining whether or not asterisks can be added to make the first produce the second, when interpreted as a sequence of stack operations in the sense of textbook Exercise 4.6.
Convert to postfix the expression
( 5 * ( ( 9 * 8 ) + ( 7 * ( 4 + 6 ) ) ) ).
Give, in the same manner as Figure 4.2, the contents of the stack as the following expression is evaluated by Program 4.2:
5 9 * 8 7 4 6 + * 2 1 3 * + * + *.
Prove by induction that Program 4.2 correctly evaluates any postfix expression.
Write a program that converts a postfix expression to infix, using a pushdown stack.
Implement an interpreter for a programming language where each program consists of a single arithmetic expression preceded by a sequence of assignment statements with arithmetic expressions involving integers and variables named with single lower case characters. For example, given the input:
(x = 1) (y = (x + 1)) (((x + y) * 3) + (4 * x))your program should print the value 13.
A letter means put and an asterisk means get in the sequence
E A S * Y * Q U E * * * S T * * * I O * N * * *.Give the sequence of values returned by the get operations when this sequence of operations is performed on an initially empty FIFO queue.
An uppercase letter means put at the beginning, a lowercase letter means put at the end, a plus sign means get from the beginning, and an asterisk means get from the end in the sequence
E A s + Y + Q U E * * + s t + * + I O * n + + *.Give the sequence of values returned by the get operations when this sequence of operations is performed on an initially empty deque.
Write a recursive program to compute lg(N!).
Modify Program 5.1 to compute N! mod M, so that overflow is no longer an issue. Try running your program for M = 997 and N = 103, 104, 105, and 106 in order to get an indication of how your programming system handles deeply nested recursive calls.
Provide a nonrecursive implementation of Euclid's algorithm.
Give the recursive depth of Euclid's algorithm when the input values are two consecutive Fibonacci numbers (FN and FN+1).
Write a recursive program to evaluate postfix expressions.
Write a recursive program to evaluate infix expressions. You may assume that operands are always enclosed in parentheses.
Write a recursive program that converts infix expressions to postfix.
Write a recursive program that converts postfix expressions to infix.
Given two sequences, give an algorithm for determining whether or not it is possible to add plus signs and asterisks to make the first produce the second when interpreted as a sequence of deque operations in the sense of Exercise 4.36.
Back to the list of assignments.