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

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

View Full Document Right Arrow Icon
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.
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
Problem 2 b) class ArrayQueueAsStack implements Stack { private ArrayQueue queueOne = new ArrayQueue(); private ArrayQueue queueTwo = new ArrayQueue();
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern