mid1_solution

mid1_solution - COP-3530 DATA STRUCTURES AND ALGORITHMS...

This preview shows pages 1–4. Sign up to view the full content.

COP-3530 DATA STRUCTURES AND ALGORITHMS Instructor: Manuel Bermúdez Fall 2009 MIDTERM EXAM 1 Solution & Grading Policy If you have any questions about grading and re-grading, contact Ting ( [email protected] ) for problem 1,4,5 and Hadi ( [email protected] ) for problem 2,3.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem 1 (10pts) a) Quadratic The first n++ line will be executed i times for each 0 < i < x, which adds up to (1+2+...+(x-1)) = x*(x-1)/2 The second one will be executed x times only. So n will be incremented x*(x-1)/2 + x = x(x+1)/2 times, hence f(x)=x(x+1)/2. So the answer is quadratic. Note that the question is asking you to find f(x) as a function of x, which in general is different than asking for a functions runtime complexity - but in this case they are the same. Grading Policy: 1. 5pts: correct answer but no justification 2. 1-3 pts: wrong answer but reasonable justification 3. 7-9 pts: correct answer but not so well justified
Problem 2 b) class ArrayQueueAsStack implements Stack { private ArrayQueue queueOne = new ArrayQueue(); private ArrayQueue queueTwo = new ArrayQueue();

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern