CPSC 221H-200: Data Structures & Algorithms
Homework Assignment #1
Spring 2009
General Guidelines for Homework
-
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.
-
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.
-
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.
Assigned Problems
Due: Thursday January 29, 2009 at the beginning of class
-
Problem R-4.8 in the text (p. 196).
(20 points)
-
Problem R-4.10 in the text (p. 196).
(20 points)
-
Problem C-4.9 in the text (p. 199).
(30 points)
-
Design a version of the size() operation of a stack that used
only pop(), push(obj), and isEmpty() operations, and does not use
any internal variable of the underlying array (i.e., you
cannot use the implementation of size() in the text).
Express your algorithm using pseudo-code, including
comments to explain the various steps.
What is the running time of your size() operation assuming there
are N elements in the stack when size() is invoked.
Express your answer using asymptotic notion.
Compare the efficiency of this new version of size()
with the version in the text that uses the internal
variable t. Which one is more efficient?
You MUST explain your reasoning to obtain full credit.
(30 points)
Bonus Problems
Due by Thursday February 12, 2008
These problems can be done for extra credit.
Points for bonus problems will be tabulated separately, and
will be considered separately at the end of the semester.
They should be turned in separately from your
regular assignment. They will be accepted upto two weeks
past the due date of the assignment.
- Bonus Problem 1:
Problem C-4.6 in the text (p. 198). (10 points)