exam1_solution - COP 3530 Midterm Part 1(Mar 3 2008...

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

View Full Document Right Arrow Icon
COP 3530 Midterm, Part 1 (Mar 3, 2008) SOLUTION: . 1. (10 points) Define the term in-place , as it applies to sorting algorithms. Give an example of a sorting method that is not in-place. Solution: An in-place sorting algorithm uses no extra workspace. Merge-sort is not in-place. 2. (15 points) Suppose you are searching for an item that appears more than once in the list. Which one will be found by a sequential (linear time) search? Which one will be found by a binary search? Answer as precisely as possible. Solution: Assuming the sequential search goes from i = 0 to n - 1, the value with the smallest index will be found. For binary search, there is no guarantee which will be returned. 3. (20 points) Write an algorithm that takes as input an array of n real numbers that is known to be sorted in ascending order, and sorts the array in descending order instead. You may assume that n is even. Use no additional size- n workspace. What is the time complexity of your algorithm?
Image of page 1

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

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