One of possible case for multiplying two integers without using '*' operator.
Case:1 Recursively add x y time.
int mul(int x, int y)
{
if(y == 0 || x==0)
return 0;
if(y > 0 )
return (x + mul(x, y-1));
if(y < 0 )
return mul(-x, -y);
}
Time complexity of above function is O(y).
case 2:swap x and y if x is lower than y.
int mul(int x,int y,int mult){
if(y==0)
return mult;
if(y<0){
x=-x;
y=-y;
}
return mul(x,y-1,mult+x);
}
Case 3:We have alternative which is optimal.
mul(x,y)
{
if(x==0||y==0)
return 0;
if (y == 1)
return x;
if (y % 2 == 0)
return mul(x + x, y >> 1);
else
return x + mul(x + x, y >> 1);
}
Time complexity of this function is O(log(y)).