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 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.