Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching

Similar presentations


Presentation on theme: "Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching"β€” Presentation transcript:

1 Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Modular arithmetic Today: Exponentiation Multiplicative Inverses Extended Euclid’s algorithm CMPSC 360 11/29/2018

2 Modular exponentiation
Naive algorithm to compute π‘₯ 𝑦 mod π‘š. mod-exp-naive(𝒙,π’š,π’Ž) Input: integer 𝒙, natural number π’š, positive integer π’Ž. if π’š=𝟎 then return 1 else 𝒛= mod-exp-naive(𝒙,π’šβˆ’πŸ,π’Ž) return (𝒛⋅𝒙 mod π’Ž) 11/29/2018

3 I-clicker problem (frequency: BC)
If 𝑦 has 𝑏 bits, how many multiplications mod π‘š are performed when we compute π‘₯ 𝑦 mod π‘š by the naive algorithm? Find the largest correct bound: At least βˆšπ‘. At least 𝑏. At least 2𝑏. At least 𝑏 2 . At least 2 π‘βˆ’1 . 11/29/2018

4 Modular exponentiation
Uses repeated squaring to compute π‘₯ 𝑦 mod π‘š. mod-exp(𝒙,π’š,π’Ž) Input: integer 𝒙, natural number π’š, positive integer π’Ž. if π’š=𝟎 then return 1 else 𝒛= mod-exp(𝒙,π’š div 𝟐,π’Ž) if π’š mod 2 =𝟎 then return (𝒛⋅𝒛 mod π’Ž) else return (𝒛⋅𝒛⋅𝒙 mod π’Ž) 11/29/2018

5 I-clicker problem (frequency: BC)
If 𝑦 has 𝑏 bits, how many multiplications mod π‘š are performed when we compute π‘₯ 𝑦 mod π‘š by repeated squaring? Find the smallest correct bound: At most βˆšπ‘. At most 𝑏. At most 2𝑏. At most 𝑏 2 . At most 2 π‘βˆ’1 . 11/29/2018

6 Definitions If π‘₯⋅𝑦≑1 (mod π‘š) then 𝑦 is a multiplicative inverse of π‘₯ modulo π‘š. The greatest common divisor of natural numbers π‘₯ and 𝑦, denoted gcd(π‘₯,𝑦), is the largest natural number that divides both. If gcd(π‘₯,𝑦)=1 then π‘₯ and 𝑦 are relatively prime (also called coprime). 11/29/2018


Download ppt "Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching"

Similar presentations


Ads by Google