This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Computer Science I – Summer 2011 Recitation #4: Algorithm Analysis (Solutions) 1)For an O(n 3 ) algorithm, one data set with n = 3 takes 54 seconds. How long will it take for a data set with n = 5? Solution Let T(n) be the function for the run time of the algorithm. Then, T(n) = cn 3 for some constant c. T(3) = c3 3 = 54 27c = 54, so c = 2 T(5) = c5 3 = 2(125) = 250 seconds. 2)For an O(2 n ) algorithm, a friend tells you that it took 17 seconds to run on her data set on a O(2 n ) algorithm. You run the same program, on the same machine, and your data set with n = 7 takes 68 seconds. What size was her data set? Solution Let T(n) be the function for the run time of the algorithm. Then, T(n) = c2 n for some constant c. T(7) = c2 7 = 68 128c = 68, so c = 68/128 = 17/32. T(n) = c2 n = 17(2 n )/32 = 17, so 2 n = 32 and n = 5. 3)For an O(N k ) algorithm, where k is a positive integer, an instance of size M takes 32 seconds to run. Suppose you run an instance of size 2M and find that it takes 512 seconds to run. What is to run....
View
Full
Document
This note was uploaded on 09/21/2011 for the course COP 3330 taught by Professor Staff during the Spring '08 term at University of Central Florida.
 Spring '08
 Staff
 Computer Science

Click to edit the document details