The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+13 votes
1.3k views

If $n$ is a power of $2$, then the minimum number of multiplications needed to compute $a^n$ is

  1. $\log_2 n$
  2. $\sqrt n$
  3. $n-1$
  4. $n$
asked in Algorithms by Veteran (59.7k points)
edited by | 1.3k views

2 Answers

+25 votes
Best answer
a. $\log n$

$a^n = (a^2)^{\frac{n}{2}}$.

One multiplication and recurrence on $\frac{n}{2}$. So, we get the recurrence relation for the number of multiplications as

$T(n) = T(n/2) + 1$.

This gives $T(n) = \log_2 n$

For n = 8, we can do

$b = a \times a$

$b = b\times b$

$b = b\times b$ and we get $b = a^8$
answered by Veteran (367k points)
edited by
+16
Using Recurrence:

$a^n = a^{\frac{n}{2}}.a^{\frac{n}{2}}$
(here n is in a power of 2, so we would never have a fraction, each time when we divide n with 2.)

Here once we solve $a^{\frac{n}{2}}$, then we need one more multiplication that is multiplying $a^{\frac{n}{2}}$ to itself.

Hence recurrence:
T(n) = T$(\frac{n}{2})$+1.
Option 1 satisfies this.
0

n is a power of 2 .

So, $a_{n}$ could be $\left (2^{x} \right )^{n}$

Now, if we think $\left (2^{x} \right )^{n}$=$2^{m}$

Now,

$T\left ( 2^{m} \right )=T\left (2 ^{\frac{m}{2}} \right )+1$

Now, applying master 2nd theorem , answer is Option (A)

+5 votes
let n = 2^k

a^n = a^(2^k) = (a^2)^k

total multiplications = k-1 + 1(for a^2) = k = logn
answered by (435 points)
0
Suppose a=2 k=3 ... So $2^{(2^{3})}$ = $2^{8}$ = 256

 and  $(2^{2})^{3}$ = $4^{3}$ = 64 .... is it ok according to ur a^(2^k) = (a^2)^k ??
0

a^(2^k) = (a^2)^k

It is wrong.

For k=3,

a^(2^k) = a^(2^3) = a^8

and

(a^2)^k = (a^2)^3 = a^6

Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,200 questions
49,671 answers
163,568 comments
65,819 users