CSE 2320 - Assignments

Not Graded Practice for Assignment 5


Practice Question 1

Modify the list-based implementation of stacks, as defined in files lists.c, stacks.h and stacks_lists.c, so that:


Practice Question 2

Modify the list implementation in lists.c and lists.h so that:

Practice Question 3

(This is Problem 4.6 from the textbook).

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.


(Challenge) Practice Question 4

(This is Problem 4.8 from the textbook).

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.


Practice Question 5

(This is Problem 4.9 from the textbook).

Convert to postfix the expression

( 5 * ( ( 9 * 8 ) + ( 7 * ( 4 + 6 ) ) ) ).


Practice Question 6

(This is Problem 4.10 from the textbook).

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


(Challenge) Practice Question 7

(This is Problem 4.14 from the textbook).

Prove by induction that Program 4.2 correctly evaluates any postfix expression.


Practice Question 8

(This is Problem 4.15 from the textbook).

Write a program that converts a postfix expression to infix, using a pushdown stack.


(Challenge) Practice Question 9

(This is Problem 4.17 from the textbook).

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.


Practice Question 10

(This is Problem 4.31 from the textbook).

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.


Practice Question 11

(This is Problem 4.34 from the textbook).

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.


Practice Question 12

(This is Problem 5.1 from the textbook).

Write a recursive program to compute lg(N!).


Practice Question 13

(This is Problem 5.2 from the textbook).

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.


Practice Question 14

(This is Problem 5.5 from the textbook).

Provide a nonrecursive implementation of Euclid's algorithm.


Practice Question 15

(This is Problem 5.7 from the textbook).

Give the recursive depth of Euclid's algorithm when the input values are two consecutive Fibonacci numbers (FN and FN+1).


Practice Question 16

(This is Problem 5.9 from the textbook).

Write a recursive program to evaluate postfix expressions.


Practice Question 17

(This is Problem 5.10 from the textbook).

Write a recursive program to evaluate infix expressions. You may assume that operands are always enclosed in parentheses.


Practice Question 18

(This is Problem 5.11 from the textbook).

Write a recursive program that converts infix expressions to postfix.


Practice Question 19

(This is Problem 5.12 from the textbook).

Write a recursive program that converts postfix expressions to infix.


(Challenge) Practice Question 20

(This is Problem 4.36 from the textbook).

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.