Chapter 1: Problem 2
Write an algorithm that finds the \(m\) smallest numbers in a list of \(n\) numbers.
Chapter 1: Problem 2
Write an algorithm that finds the \(m\) smallest numbers in a list of \(n\) numbers.
All the tools & learning materials you need for study success - in one app.
Get started for freeAlgorithm 1.7 (nth Fibonacci Term, Iterative) is clearly linear in \(n,\) but is it a linear-time algorithm? In Section 1.3 .1 we defined the input size as the size of the input. In the case of the \(nth\) Fibonacci term, \(n\) is the input, and the number of bits it takes to encode \(n\) could be used as the input size. Using this measure the size of 64 is \(\lg 64=6,\) and the size of 1024 is \(\lg 1024=\) 10\. Show that Algorithm 1.7 is exponential-time in terms of its input size. Show further that any algorithm for computing the \(nth\) Fibonacci term must be an exponential-time algorithm because the size of the output is exponential in the input size. See Section 9.2 for a related discussion of the input size.
Let \(p(n)=a_{4} n^{4}+a_{k-1} n^{k-1}+\dots a_{1} n+a_{0},\) where \(a_{k}>0 .\) Using the Properties of Order in Section \(1.4 .2,\) show that \(p(n) \in \Theta\left(n^{k}\right)\)
Discuss the reflexive, symmetric, and transitive properties for asymptotic comparisons \((O, \Omega, \theta, o)\)
What is the time complexity \(T(n)\) of the nested loops below? For simplicity, you may assume that \(n\) is a power of \(2 .\) That is, \(n=2^{k}\) for some positive integer \(k\) : \\[ \begin{array}{l} i=n_{i} \\ \text { while }(i>=1)\\{ \\ \qquad \begin{array}{c} j=i \\ \text { while }(j<=n) \end{array} \end{array} \\] < body of the inner while loop> \(\quad\) I/ Needs \(\Theta(1)\) \\[ j=2^{*} j \\] } \\[ i=|1 / 2| \\] }
Give an algorithm for the following problem. Given a list of \(n\) distinct positive integers, partition the list into two sublists, each of size \(n / 2,\) such that the difference between the sums of the integers in the two sublists is minimized. Determine the time complexity of your algorithm. You may assume that \(n\) is a multiple of 2
What do you think about this solution?
We value your feedback to improve our textbook solutions.