
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Professor: Horton; Class: Algorithms; Subject: Computer Science; University: University of Virginia; Term: Unknown 1989;
Typology: Quizzes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Answer the questions below before the end of class and turn it in. The results you give will not count toward your grade in the class. The purpose of this test is for me to get a feel for how well the class overall understands this material, and for you to see how well you understand this material.
So A(n) = 1 x 0.5 + Sum_{i=2 to n} (0.5 x i / (n-1))
Argue that one cannot find the minimum element in an unsorted array of size n without doing at least n-1 comparisons. To find the minimum you must show that the other n-1 items are not the minimum, which implies that they win when compared to some other item. One comparison produces exactly one winner, so you need n-1 comparisons.
Selection sort works by finding the largest element in an array from position 0 to position n-1, moving it to the end of the array, and then repeating this process with the sub-array from 0 to n-2, etc.
(A) Given what you know about FindMax, how many comparisons does selection sort do? Sum_{i=1 to n-1} (n-i) = Sum{i=1 to n-1} i = n(n-1)/
(B) FindMax is optimal: does this imply selection sort is optimal? No!
Show that any polynomial grows more slowly than any exponential (see the slide) using the method shown in class using limits and L'Hopital's rule. This is problem O5 of HW1. See solution posted for that. (Doh! I didnโt mean to put this hard a problem on this quiz! I meant you to compare log n to n here.)
How often is x incremented in the following code? for i = 1 to n for j = i downto 1 x = x + 1 Sum_{i=1 to n} (i) = n(n+1)/
How often is x incremented in the following code? j = n while (j >= 1) { for i = 1 to j x = x + 1 j = j / 2 } See page 49-50 in the textbook. If n is a power of 2, this is just 2(n-1)