thanks to all
On Tue, Aug 9, 2011 at 8:45 PM, shady wrote:
> he is questioning the complexity and not the algorithm... btw, you are
> right
>
>
> On Tue, Aug 9, 2011 at 8:41 PM, Don wrote:
>
>> I don't think that this function is doing what you want it to do. If
>> you ask for a^b, it returns a
he is questioning the complexity and not the algorithm... btw, you are right
On Tue, Aug 9, 2011 at 8:41 PM, Don wrote:
> I don't think that this function is doing what you want it to do. If
> you ask for a^b, it returns a^1 in most cases.
>
> Try this instead.
>
> int power(int a, int b)
> {
>
I don't think that this function is doing what you want it to do. If
you ask for a^b, it returns a^1 in most cases.
Try this instead.
int power(int a, int b)
{
int result = 1;
if (b == 1) result = a;
else if (b>1)
{
result = power(a,b/2);
result *= result;
if (b%2) result *= a
@Dipankar: And O(log 5) = 1, so the complexity is O(p).
Dave
On Aug 8, 10:43 pm, Dipankar Patro wrote:
> This is a simple one:
>
> get_power has a complexity of O(logb), since it is dividing b by 2 each time
> it is called.
> and the get_power func is called for p times.
>
> the overall complexi