CSE 2320 - Assignments

Not Graded Practice for Assignment 4

This is a set of practice questions. Feel free to work on these questions, and to ask questions if you face any difficulties in coming up with answers. While collaboration with others on the graded homework is strictly prohibited, you are free to work on these practice questions together with other people.

Since they are practice questions, you do not have to, and should not, submit answers to these questions on Blackboard. These questions will not be considered in any way towards your course grade. At the same time, based on the instructor's experience, individuals spending substantial and systematic effort in answering these practice questions by themselves tend to significantly improve their overall class performance.


Practice Question 1

(This is Problem 3.59 from the textbook).

Write a function that takes a string as an argument and reads a sequence of words (sequences of characters separated by blank space) from standard input, printing out those words that appear as substrings somewhere in the parameter string.


Practice Question 2

(This is Problem 3.62 from the textbook).

Write an efficient function that takes a string as an argument and returns the length of the longest sequence of blanks in that string, examining as few characters in the string as possible. Hint: Your program should become faster as the length of the sequence of blanks increases.


Practice Question 3

(This is Problem 3.65 from the textbook).

Write a program to fill in a two-dimensional array of 0-1 values by setting a[i][j] to 1 if the greatest common divisor of i and j is 1, and to 0 otherwise.


Practice Question 4

(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 5

(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 6

(This is Problem 4.9 from the textbook).

Convert to postfix the expression

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


Practice Question 7

(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 8

(This is Problem 4.14 from the textbook).

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


Practice Question 9

(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 10

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


Back to the list of assignments.