Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Find the Complexity of the given snippet.
- what are the time complexities of following
- 1.
- void function(int n)
- {
- int count = 0;
- for (int i=0; i<n; i++)
- for (int j=i; j< i*i; j++)
- if (j%i == 0)
- {
- for (int k=0; k<j; k++)
- printf("*");
- }
- }
- 2.
- int gcd(int n, int m)
- {
- if (n%m ==0) return m;
- if (n < m) swap(n, m);
- while (m > 0)
- {
- n = n%m;
- swap(n, m);
- }
- return n;
- }
- 3.
- void pat(){
- for (int i = 2; i <=n; i = pow(i, c)) {
- print("*")
- }
- //Here fun is sqrt or cuberoot or any other constant root
- for (int i = n; i > 1; i = fun(i)) {
- print("*")
- }
- }
- 4.
- int count = 0;
- for (int i = N; i > 0; i /= 2)
- for (int j = 0; j < i; j++)
- count++;
- 5.
- 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.
- 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