Homework Assignment 2
Assignment
-
(50 points) Give a recursive method for removing all the elements from a
stack.
- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
-
(50 points) Postfix notation is an unambiguous way of writing an arithmetic
expression without parenthesis. It is defined so that if
(exp1) op (exp2)
is a normal fully parenthesized expression whose operation isop
, the postfix notation ispexp1 pexp2 op
, wherepexp1
is the postfix version ofexp1
andpexp2
is the postfix version ofexp2
. So, for example, the postfix version of((5+2)*(8-3))/4
is5 2 + 8 3 - * 4 /
. Describe a nonrecursive way of evaluating an expression in postfix notation.- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
-
Bonus.
(10 points) Suppose you have a stack
S
containingn
elements and a queueQ
that is initially empty. Describe how you can useQ
to scanS
to see if it contains a certain elementx
, with the additional constraint that your algorithm must return the elements back toS
in their original order. You may only useS
,Q
, and a constant number of other primitive variables.- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
General Instructions, Turning in assignments, and Grading
General Instructions
- All homework assignments must be typeset using LaTex. Using another
program (e.g., Microsoft Word) or handwriting assignments will result in
grade of 0. Here is an example homework
problem (click here for pdf) worked out to see the expected format and
the tex file (click here to see it) that
generated it to help you start.
- If you are unfamiliar with LaTex, here is a short tutorial (click here for pdf) and the tex file (click here to see it) that generated it. This tutorial shows how to write common mathematics, how to write pseudocode, how to cite sources, how to include images, and how to include tables.
- Complete every part of every problem!
- On writing an algorithm, use pseudocode and good mathematical style to describe algorithms and data structures. Do not specify Java code unless otherwise stated.
- On time complexity, your goal should be to determine and prove the tightest bound for your algorithm. Be sure to state any assumptions about implementations needed.
- On memory complexity, your goal is to analyze the extra memory consumed by your algorithm, i.e., do not count the memory used by the input to your algorithm.
- Follow turn-in instructions precisely.
- Failure to complete any of these steps will result in a significant loss of points.
Turn in Instructions
Each assignment will be turned in in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean one minute after class starts. Details:
- The first page of your hard copy must be a signed coverpage (click here for pdf).
- Next put the problems in order as described in the description. This may seem silly, but you would be surprised sometimes.
- If you do not know how to print, consult University of Richmond webpages to learn how to use campus printers. If possible, please print 2-sided. Printer issues are not an excuse to turn an assignment in late.
- Staple all pages together.
- I reserve the right to assign a 0 to any assignment failing to comply with these instructions. Even for something as small as a missing staple.
Grading
- Each assignment is graded out of 100 points (not including bonus).
- Expectation and point distribution - this is a general guideline that may
change depending on the specific problem, e.g., proof-only problems may
differ.
- Algorithm description and pseudocode - ~50%
- Provide a written explanation of your algorithmic solution. Provide intuition as to why it computes the correct answer.
- Provide pseudocode of your solution. Be sure to clearly state input and output (if applicable, and a return statement must also be present), and be sure to use ADTs as specified in slides and textbook.
- Statement and proof of time complexity - ~25%
- Provide a theorem/lemma stating assumptions and results.
- Provide a clear proof sketch justifying theorem.
- Statement and proof of memory complexity - ~25%
- Provide a theorem/lemma stating assumptions and results.
- Provide a clear proof sketch justifying theorem.
- Algorithm description and pseudocode - ~50%
- Criteria (includes but is not limited to)
- Efficiency solutions - inefficient algorithms will yield partial credit to the problem.
- Clear and concise technical writing and presentation is the heart of the grade. It is not merely that you solve the problem, it is a function of how well you write your pseudocode and theorems, and how they are explained and proved. Short statements of fact and clear equations are valued over unclear, complex, and lengthy expositions.
- Proper use of LaTeX is also expected. Points will be deducted for not using mathematics mode or LaTeX tables for example.
- If there are any discrepancies in grades, please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).