Chapter 1: Problem 6
Write an algorithm that finds both the smallest and largest numbers in a list of \(n\) numbers. Try to find a method that does at most \(1.5 n\) comparisons of array items.
Chapter 1: Problem 6
Write an algorithm that finds both the smallest and largest numbers in a list of \(n\) numbers. Try to find a method that does at most \(1.5 n\) comparisons of array items.
All the tools & learning materials you need for study success - in one app.
Get started for freeThere are two algorithms called Algl and Alg2 for a problem of size n. Algl runs in \(n^{2}\) microseconds and Alg2 runs in 100 n log \(n\) microseconds. Algl can be implemented using 4 hours of programmer time and needs 2 minutes of CPU time. On the other hand, Alg2 require 15 hours of programmer time and 6 minutes of CPU time. If programmers are paid 20 dollars per hour and CPU time costs 50 dollars per minute, how many times must a problem instance of size 500 be solved using Alg2 in order to justify its development cost?
Explain in English what functions are in following sets. a. \(n^{O(1)}\) b. \(O\left(n^{O(1)}\right)\) c. \(O\left(O\left(n^{O(1)}\right)\right)\)
Write an algorithm that finds the greatest common divisor of two integers.
Presently we can solve problem instances of size 100 in 1 minute using algorithm \(A,\) which is a \(\Theta\left(2^{n}\right)\) algorithm. On the other hand, we will soon have to solve problem instances twice this large in 1 minute. Do you think it would help to buy a faster (and more expensive) computer?
Show directly that \(f(n)=n^{2}+3 n^{3} \in \Theta\left(n^{3}\right)\). That is, use the definitions of \(O\) and \(\Omega\) to show that \(f(n)\) is in both \(O\left(n^{3)} \text { and } \Omega\left(n^{3)}\right.\right.\)
What do you think about this solution?
We value your feedback to improve our textbook solutions.