Chapter 1: Problem 3
Write an algorithm that prints out all the subsets of three elements of a set of \(n\) elements. The elements of this set are stored in a list that is the input to the algorithm.
Chapter 1: Problem 3
Write an algorithm that prints out all the subsets of three elements of a set of \(n\) elements. The elements of this set are stored in a list that is the input to the algorithm.
All the tools & learning materials you need for study success - in one app.
Get started for freeShow the correctness of the following statements. (a) \(\lg n \in O(n)\) (b) \(n \in O(n \lg n)\) (c) \(n \lg n \in O\left(n^{2}\right)\) (d) \(2^{n} \in \Omega\left(5^{\ln n}\right)\) (c) \(\lg ^{3} n \in o\left(n^{a \cdot 5}\right)\)
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
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 about \(1.5 n\) comparisons of array items.
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| \\] }
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}\right)\) and \(\Omega\left(n^{3}\right)\)
What do you think about this solution?
We value your feedback to improve our textbook solutions.