Guest User

Untitled

a guest
Dec 28th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. Find the Complexity of the given snippet.
  2. what are the time complexities of following
  3. 1.
  4.  
  5.  
  6.        void function(int n)
  7.        {
  8.          int count = 0;
  9.  
  10.          for (int i=0; i<n; i++)
  11.          for (int j=i; j< i*i; j++)
  12.              if (j%i == 0)
  13.              {
  14.                 for (int k=0; k<j; k++)
  15.                      printf("*");
  16.               }
  17.         }
  18. 2.
  19.  
  20.  
  21.  
  22.  int gcd(int n, int m)
  23.  {
  24.      if (n%m ==0) return m;
  25.      if (n < m) swap(n, m);
  26.         while (m > 0)
  27.         {
  28.           n = n%m;
  29.           swap(n, m);
  30.         }
  31.       return n;
  32.   }
  33.  
  34.   3.
  35.  
  36. void pat(){
  37.  
  38.    for (int i = 2; i <=n; i = pow(i, c)) {
  39.       print("*")
  40.    }
  41.  
  42. //Here fun is sqrt or cuberoot or any other constant root
  43.    for (int i = n; i > 1; i = fun(i)) {
  44.      print("*")
  45.    }
  46. }
  47. 4.
  48. int count = 0;
  49. for (int i = N; i > 0; i /= 2)
  50.     for (int j = 0; j < i; j++)
  51.         count++;
  52.        
  53. 5.
  54. Frequently, the memory space required by an algorithm is a multiple of the size of input. State if the statement is True or False or Maybe.
  55. 6.The running time of an algorithm is given by T(n) = T(n - 1) + T(n - 2) - T(n - 3), if n > 3 n, otherwise.
Add Comment
Please, Sign In to add comment