Question

In: Computer Science

What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n...

What are Big-O expressions for the following runtine functions?

     a) T(n)= nlog n + n log (n2 )  

     b) T(n)= (nnn)2     

     c) T(n)= n1/3 + n1/4 + log n

     d) T(n)= 23n + 32n

     e) T(n)= n! + 2n

Write algorithm and program : Find the sum of the integers from 1 through n.

    a)Use iterative algorithm and program

        b) Use recursive algorithm and program.

  1. Order the following functions by growth rate:
    1. 3n
    2. n
    3. n2
    4. 5
    5. n1.3
    6. n log n2
    7. 2n
    8. 2n/2
    9. n2log n
    10. n3

Solutions

Expert Solution

Solution1.:-

T(n) = nlog n + n log (n2 )  

T(n) = nlog n + n log (n2 )  

= nlogn + 2n log n = 3nlog n = O(nlog n)

T(n)= (nnn)2 T(n) = (nnn)2 = (n3)2 = n6 = O(n6)
T(n)= n1/3 + n1/4 + log n T(n) = O(n1/3)
T(n)= 23n + 32n T(n) = O(32n)
T(n)= n! + 2n T(n) = nn + 2n = O(nn)

Solution 2. :

Iterative Algorithm: 1. Take variable sum = 0

2. For each number from 1 to n add each number to variable sum

3. return sum

Iterative Program:

#include <iostream>

using namespace std;
int main() {
  int sum= 0,n;
  cout<<"Enter value of 'n':"<<endl;
  cin>>n;
  for(int i=1;i<=n;i++)
    sum+=i;
  cout<<"Sum: "<<sum<<endl;
}

  Recursive Algorithm:

1. if n = 1, return 1. Else go to step 2

2. add 'n' to the result returned by recursion on n = n-1

  Recursive Program:

#include <iostream>

using namespace std;
int recurSum(int n) 
{ 
    if (n <= 1) 
        return n; 
    return n + recurSum(n - 1); 
}    
int main() {
  int sum= 0,n;
  cout<<"Enter value of 'n':"<<endl;
  cin>>n;
  cout<<"Sum: "<<recurSum(n)<<endl;
}

Solution 3:-

5 < n < nlog n2< n1.3 < n2 < n2 log n < n3 < 2n/2 < 2n < 3n


Related Solutions

Here are some basic rules for calculating the Big O for some T(n) or an algorithm....
Here are some basic rules for calculating the Big O for some T(n) or an algorithm. 1. Only the highest degree of n matters. For example T(n) = n^3 + 5n^2 + 107 → O(n^3 ) since once n becomes super-massively huge, the other terms just stop mattering. 2. Constant factors don’t matter. T(n) = 500n and T(n) = 0.005n both O(n). Again, as n becomes bigger, these constants stop mattering; what matters is the rate of growth. Example: T(n)...
Show for the following recurrence that T(n) = T(n/3) + n*log(n) is O(n*log(n)) (not using the...
Show for the following recurrence that T(n) = T(n/3) + n*log(n) is O(n*log(n)) (not using the Master theorem please)
Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2....
Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2. 100nlog n + n5 + 100n 3. n2log n + nlog n 4. 2n + n5 + 5n 5. 100n + 0.01n2 A. O(n3) B. O(5n) C. O(n2) D. O(n5) E. O(n2log n)
What is the Big O of the following algorithms along with the worst and average cases:...
What is the Big O of the following algorithms along with the worst and average cases: Euclid's Algorithm Brute-Force Matching Topological Sort Lomuto Partition Russian Peasant Algorithm
Justify the following statements using the "big-Oh" definition: a) (n+25)2 is O(n2) , and n2 is...
Justify the following statements using the "big-Oh" definition: a) (n+25)2 is O(n2) , and n2 is O((n+25)2) b) n3 is NOT O(n2); c) Given f1(n) is (n+25)2 , and f2(n) is n3 what is the big-Oh for f1(n) x f2(n)?
A) What is the big O for the following: f(n)=5n2+logn+1 i)n^2 ii)1 iii)logn iv)5n2+logn+1 B) Given...
A) What is the big O for the following: f(n)=5n2+logn+1 i)n^2 ii)1 iii)logn iv)5n2+logn+1 B) Given two algorithms with the following running time:Algorithm A: Ta(n)=4n+20 andAlgorithm B: Tb(n)=2n2+10Which of the following statements are correct? i)Algorithm A is faster than algorithm B for n > 100. ii)Algorithm B is faster than algorithm A for n > 100. C) A function template can operate with: i)an integer ii)any type of data iii)a string iv)a Rectangle object
1. Find the big−O, big−Ω estimate for x7y3+x5y5+x3y7. [Hint: Big-O, big- Θ, and big-Omega notation can...
1. Find the big−O, big−Ω estimate for x7y3+x5y5+x3y7. [Hint: Big-O, big- Θ, and big-Omega notation can be extended to functions in more than one variable. For example, the statement f(x, y) is O(g(x, y)) means that there exist constants C, k1, and k2 such that|f(x, y)|≤C|g(x, y)|whenever x > k1 and y > k2] 2. Find a div b and a mod b when: (a) a = 30303, b = 333 (b) a = −765432, b = 3827 3. Convert...
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n);...
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n); ω(n); ϴ(n)
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 +...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 + n)(n ^2 + π/2 ) 3. 1 + 2 + 3 + · · · + n − 1 + n
Consider the following binds Ca-O, C-O, K-O, O-O and N-O a Which bonds are polar covalent...
Consider the following binds Ca-O, C-O, K-O, O-O and N-O a Which bonds are polar covalent ? b Wich bonds are nonpolar Covalent c Which bonds are ionic ? d Arrange the covalent bonds in order of decreasing polarity
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT