No Explaination.

Consider the program below:

#include<stdio.h>

int fun (int n, int *fp)

{

int t, f;

if ( n<= 1)

{

*fp = 1;

return 1;

}

t = fun(n - 1, fp);

f = t+ * fp;

*fp = t;

return f;

}

int main( )

{

int x = 15;

printf (“%d\n”, fun (5, &x));

return 0;

}

The value printed is

No Explaination.

Which one of the following represents the time complexity of the algorithm?

No Explaination.

No Explaination.

#include <stdio.h>

void f (int * p, int * g) {

p = q;

* p = 2;

}

int i = 0, j = 1;

int main ( ){

f(&i, & j);

print f ("%d %d \ n", i, j);

return 0;

}

No Explaination.

No Explaination.

unsigned int foo unsigned int n, unsigned int r {

if (n > 0) return (n%r) + foo (n / r, r ));

else return 0;

}

What is the return value of the function foo when it is called as foo (513, 2)?

unsigned int foo unsigned int n, unsigned int r {

if (n > 0) return (n%r) + foo (n / r, r ));

else return 0;

}

What is the return value of the function foo when it is called as foo (345, 10) ?

The average case time can be lesser than or even equal to the worst case. So A(n) would be upper bounded by W(n) and it will not be strict upper bound as it can even be same (e.g. Bubble Sort and merge sort). ∴A(n) = O(W(n))

Let the three pegs be A,B and C, the goal is to move n pegs from A to C using peg B The following sequence of steps are executed recursively 1.move n−1 discs from A to B. This leaves disc n alone on peg A --- T(n-1) 2.move disc n from A to C---------1 3.move n−1 discs from B to C so they sit on disc n----- T(n-1) So, T(n) = 2T(n-1) +1