
ASSIGNMENT #1 SOLUTION
Fill in the Blank.
1. Name: (1 point)
2. I have satisfied the prerequisites of CS 303 Algorithms and Data Structures and CS 350
Formal Languages and Automata, or equivalent, each with a grade of C or better.
Signature: (2 points)
True or False.
For each of the problems below, indicate whether it is true or false. Justify your answer in either
case. (3 points each)
3. A context-free grammar defining a deterministic context-free language may always be con-
verted into a deterministic pushdown automaton.
False. The algorithm which converts a CFG into a PDA will always produce a nondetermin-
istic PDA.
4. The context-free grammar below is ambiguous.
Sโif (e) S|if (e) Selse S|s
True. The following are two distinct left-most derivations of the same string.
Sโif (e) Sโif (e) if (e) Selse Sโif (e) if (e) selse Sโif (e) if (e) selse s
Sโif (e) Selse Sโif (e) if (e) Selse Sโif (e) if (e) selse Sโif (e) if (e) selse s
5. It is not possible to implement a tree data structure where interior nodes have an arbitrary
number of children (e.g. some nodes may have 1 child, some 2, some 3, etc.).
False. The children may be represented by a list.
Short Answer.
6. Assume a binary tree object with functions value,left and right to return the value of
the current node, left subtree, and right subtree, respectively. Using an actual programming
language or pseudo-code, write a function postorder to print the values of all nodes in the
tree using a post-order traversal. Please write your answer on back. (3 points)
void postorder () {
if (left () != null) left () . postorder ();
if (right () != null) right () . postorder ();
System . out . print (value ());
}