CPSC 221H-200: Data Structures & Algorithms
Programming Assignment #2
Spring 2009
General Guidelines for Programs
-
Your code should be well designed and documented. You WILL be graded
on programming style.
-
If the question is not fully specified, you may need to make
some assumptions. In this case, you must state any assumptions you
make, and justify why they are reasonable.
-
Everyone must turn in their own copy of the assignment. You may consult
outside material or work with others (this is encouraged), but you
must reference your sources (people, books, webpages, etc.).
These must be listed on the cover sheet mentioned below.
-
Be clear and precise. Write neatly and legibly.
Justify all answers, even if not specified in the question.
Use good judgement concerning how detailed to make your answer.
-
Code will be turned in electronically using the
turnin program on CSNet.
-
The report portion of the assignment, if any, follows conventions
for other written assignments in this course.
In particular, all assignments in this course must include
a completed and signed
coverpage
available on the course homepage.
Any assignment turned in without a fully completed and signed
coverpage will receive ZERO POINTS.
Assignment
Due: Monday February 16, 2009 by 11:59pm.
Code should be turned in electronically using the mechanism described above.
You should also turn in an electronic copy of your report using the same
mechanism as you do for the code; the electronic copy does not need to
have the signed coverpage.
In addition, you should submit a hardcopy of your report (but no code).
This is due at the beginning of lab on February 17, 2009; the hardcopy
must include the signed coverpage.
This programming assignment concerns a doubly-linked list implementation of
the List ADT.
You will add variants of two of the existing list operations
insertLast() and insertBefore()
that use different implementions and you will compare the
performance of your versions, myInsertLast() and myInsertBefore(),
with the already provided insertLast() and insertBefore().
This will give you practice implementing linked lists and will
allow you to see how the choice of implementation can
affect performance.
Coding Portion. (50 points)
-
Start with the following template programs:
NodeList.h and
RuntimeException.h,
and complete the implementations of the methods
myInsertLast() and myInsertBefore() in NodeList.h.
Your implementations of myInsertLast() and myInsertBefore()
should only use combinations of the functions
isEmpty(), nodePtr(), insertAfter(), First(), and insertFirst().
You can only insert elements using insertAfter() and insertFirst().
You are NOT allowed to use the header or trailer data members,
but you are allowed to use the next, previous and element
data members of the Node structure.
You will need to use the Position constructor.
You should turn in your modified version of NodeList.h
and the test program you used to generate the results
you report for question 3.
The program
TestNodeList.cpp
(p. 224 text) is a good example of how to use the list that
you may find useful.
Report. (50 points)
You will write a brief report that includes theoretical analysis,
a description of your experiments, and discussion of your results.
At a minimum, your report should include the following sections:
-
Introduction.
In this section, you should
describe the objective of this assignment.
-
Theoretical analysis.
In this section, you should
provide an analysis of the running time of your myInsertLast()
and myInsertBefore() methods
assuming there are N elements in the list when the functions are invoked.
Express your answer using asymptotic notion.
Compare the theoretical efficiency of these new versions of myInsertLast()
and myInsertBefore() methods with the provided
implementations of insertLast() and insertBefore().
You must explain your reasoning to receive full credit.
-
Experimental Setup.
In this section, you should
provide a description of your experiment setup, which includes but
is not limited to
- Machine specification.
- What experiments did you run and why? That is, explain what you
believe you will learn from each experiment.
- How did you generate the test inputs? What input sizes did you test? Why?
- What is your timing mechanism?
- How many times did you repeat each experiment?
-
Experimental Results.
In this section, you should
compare the performance (running time) of insertLast() and insertBefore()
and myInsertLast() and myInsertBefore(), respectively, to each other
and to their theoretical complexity.
-
Make a plot showing the running time (y-axis) vs. the
list size (x-axis) of insertLast() and myInsertLast(),
and insertBefore() and myInsertBefore(), on the same graph.
You must use some electronic tool (e.g., matlab, gnuplot, excel)
to create the plot - handwritten plots will NOT be accepted.
-
Experimentally determine the constants hidden in your asymptotic
analysis using the method described in lab; show these constants
on the plots.
Determine the values of N for which the asymptotic analysis holds;
this should also be determined from a plot.
-
Provide a discussion of your results, which includes but is
not limited to:
-
Which of the two insertLast and insertBefore operations performs the best?
Does it depend on the input?
-
To what extent does theoretical analysis agree with the experimental results?
Attempt to understand and explain any discrepancies you note.
-
Report on the constants you determined for the asymptotic analysis,
and the values of N for which you found the asymptotic analysis holds.
Explain how you determined these values, and what you can infer from
them about the behavior of this data structure.