**Programming Assignment 1
(due midnight 08/03/12)**

Penalty for late submission: 10% less credit/day.

(i) Implement the following basic data types. Follow specifications presented in the textbook in full detail.

- (10 points) Lists: two implementations, array and pointer (pages 41-46), operations: FIRST, END, RETRIEVE, LOCATE, NEXT, PREVIOUS, INSERT, DELETE, MAKENULL,
- (5 points) Stacks: two implementations, array and pointer (pages 53-56), operations: TOP, POP, PUSH, EMPTY, MAKENULL,
- (10 points) Queues: one implementation, pointer (pages 57-60), operations: FRONT, ENQUEUE, DEQUEUE, EMPTY, MAKENULL,
- (15 points) Trees: two implementations, lists of children, leftmost-child right-sibling (pages 87-93), operations: PARENT, LEFTMOST_CHILD, RIGHT_SIBLING, LABEL, CREATEi (i=0,1,2,3), ROOT, MAKENULL.

(ii) Develop the code for the following timing experiments. Report your results in the form of tables. The first column should indicate the size of the input data. The remaining columns should report the measured times for all the procedures that you apply. Derive conclusions out of your experiments and write them down.

- (15 points) Perform time measurements of the following five operations on lists: iterated insertion (in front, at the back), traversal, iterated deletion (in front, at the back). Run each of your procedures on three types of lists: a selected list type library data structure, your implementation of the list ADT with arrays, your implementation of the list ADT with pointers.
- (15 points) Perform time measurements of traversals of full trees of degree three and a given height. Run your code on both of your implementations of the tree ADT of (i).4.

(iii) Implement algorithms solving the following problems just in terms of the ADT operations of part (i).

- (5 points) 2.3 b
- (5 points) 2.4
- (5 points) 3.3 (hint: apply post-order traversal; you need to verify your code using only two representations of part (i))
- (5 points) 3.10 (hint: use a queue to store the children of visited nodes)
- (5 points) 3.13 (assume that the label of each node
consists of two fields: a unique integer identifying the node and an
identifier
*l*or*i*indicating whether a node is a leaf or an internal node) - (5 points) 3.14 ((a) prefix expression, (b) postfix expression)

Each student group needs to submit twelve separate programs and a report of timing results of part (ii). Each of the programs should contain test input data and a testing code, which demonstrate that all the operations and algorithms work properly. Use tree 3.31 (page 103) for testing the operations of the tree ADT and the solutions of problems 9,10. You will need to submit your code and your report following the submission rules that will be provided at a later date.

The choice of data representation is up to you, but you need
to preserve all the essential features of the implementations discussed in the
textbook. In particular all actions occurring in textbook implementations have
to have their counterparts in your code. Please remember trees should be
implemented with cursor type data structures and not with pointers.

Many interesting examples of C implementations directly transferable into C++
are available on the website accompanying our CS 270 textbook *Foundations of
Computer Science* by Alfred Aho and Jeffrey Ullman.

book chapters: http://infolab.stanford.edu/~ullman/focs.html

C code: http://infolab.stanford.edu/~ullman/fcsc-figures.html

Examples of Python code explaining how to substitute pointers by references are
discussed in chapters 17,19,20 of the book *How to Think Like a Computer
Scientist* by Allen Downey, Jeffrey Elkner and Chris Meyers.

http://www.greenteapress.com/thinkpython/thinkCSpy/html/