i need to prove that following algorithm works correctly,i know induction,but don’t know how to use it here?also i will be happy if would know complexity of algorithm,how optimal it is?
what is it’s run time?please help me
#include <cstdlib>
#include <iostream>
#define c 2
//we should take c more ot equal then 2
using namespace std;
int multiply(int y,int z){
// product yz
if(z==0) return 0;
return (multiply(c*y,int(z/c))+y*(z %c));
}
int main(int argc, char *argv[])
{
int y=5;
int z=7;
cout<<multiply(y,z)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
thanks
1) for
z=0your function is obviously correct2) suppose
multiply(x, y)returnsx*yfor0 <= y < y0. Then