If one of the two numbers is a power of 2 or has a power of 2 as a factor, part of the multiplication can be performed by leftshifting the bits. Still not O(1), but performance should improve in some cases..
Thats a trivial solution. basically you are adding multiple times.. the best case running time is O(n) where n is the smallest of the 2 given integers..
Write a function to multiply 2 integers without the * sign?
No.. the questions is for a way to mutliply any 2 integers.. not just power of 2's
Write a function to multiply 2 integers without the * sign?
If one of the two numbers is a power of 2 or has a power of 2 as a factor, part of the multiplication can be performed by leftshifting the bits. Still not O(1), but performance should improve in some cases..
my 2 cents
Write a function to multiply 2 integers without the * sign?
Thats a trivial solution. basically you are adding multiple times.. the best case running time is O(n) where n is the smallest of the 2 given integers..
Can you do this in O(1)
easy
#include
main()
{
int i=0;
for(int j=0;j<5;j++)
i+=2;
printf("%d",i);
return 0;
}
thanx :D