Exponentiating by squaring - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Exponentiating by squaring

Description:

Exponentiating by squaring. Raef Aidibi. CSE 670 Midterm. Winter 2004 ... It is equivalent to decomposing the exponent into a sequence of squares and products ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 7
Provided by: hask
Category:

less

Transcript and Presenter's Notes

Title: Exponentiating by squaring


1
Exponentiating by squaring
  • Raef Aidibi
  • CSE 670 Midterm
  • Winter 2004

2
  • - Used for fast computation of large powers
  • Compared to the ordinary method of multiplying x
    with itself n-1 times, this algorithm uses
    only O(lg n)
  • -Often used to compute powers of Matrices
  • - It is equivalent to decomposing the exponent
    into a sequence of squares and products

3
include ltstdio.hgt int main() int x,n,
result printf("Enter x \n") scanf("d",x)
printf("Enter n \n") scanf("d",n) result
1 while (n ! 0) // if n is odd,
multiply result with x if ((n 2) 1)
result result x x
xx n n/2 printf("result d",
result)
4
EXP
5
include ltstdio.hgt int main() int x,n,
result printf("Enter x \n")
scanf("d",x) printf("Enter n \n")
scanf("d",n) result 1 while (n ! 0)
// if n is odd, multiply result with x if ((n
2) 1) result result x x
xx n n/2
6
After BTN debounce
S2
include ltstdio.hgt int main() int x,n,
result printf("Enter x \n")
scanf("d",x) printf("Enter n \n")
scanf("d",n) result 1 while (n ! 0)
// if n is odd, multiply result with x if ((n
2) 1) result result x x
xx n n/2
Result 1
S8
S3
n0
Check on n
n!0
S7
S4
n is even
N is odd
S5
S6
Write a Comment
User Comments (0)
About PowerShow.com