MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.

Slides:



Advertisements
Similar presentations
Chapter Three: Closure Properties for Regular Languages
Advertisements

Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Cryptography and Network Security
Congruence class arithmetic. Definitions: a ≡ b mod m iff a mod m = b mod m. a  [b] iff a ≡ b mod m.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Factoring 1 Factoring Factoring 2 Factoring  Security of RSA algorithm depends on (presumed) difficulty of factoring o Given N = pq, find p or q and.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Data Structures Review Session 1
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
Data Representation Number Systems.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
MA/CSSE 473 Day 28 Hashing review B-tree overview Dynamic Programming.

MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Induction and recursion
CS 312: Algorithm Analysis Lecture #3: Algorithms for Modular Arithmetic, Modular Exponentiation This work is licensed under a Creative Commons Attribution-Share.
MA/CSSE 473 Day 22 Binary Heaps Heapsort Answers to student questions Exam 2 Tuesday, Nov 4 in class.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
Week 2 CS 361: Advanced Data Structures and Algorithms
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Chapter 1 Introduction. Goals Why the choice of algorithms is so critical when dealing with large inputs Basic mathematical background Review of Recursion.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Analysis of Algorithms
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
MA/CSSE 473 Day 19 Exam Prep. MA/CSSE 473 Day 19 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various.
MA/CSSE 473 Day 28 Dynamic Programming Binomial Coefficients Warshall's algorithm Student questions?
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
MA/CSSE 473 Day 23 Student questions Space-time tradeoffs Hash tables review String search algorithms intro.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
MA/CSSE 473 Day 06 Euclid's Algorithm. MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
CS 615: Design & Analysis of Algorithms Chapter 2: Efficiency of Algorithms.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
MA/CSSE 473 Day 07 Euclid's Algorithm. MA/CSSE 473 Day 07 Student Questions Review topics not covered in class Euclid's algorithm (if there is time) extended.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
MA/CSSE 473 Day 06 Mathematical Induction Modular Arithmetic Do question 1 on today's quiz (work with another person)
MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.
MA/CSSE 473 Day 06 DivisionPrimes Modular Arithmetic.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division Fermat's little theorem intro.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division
MA/CSSE 473 Day 06 Euclid's Algorithm.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 06 Euclid's Algorithm.
Congruence class arithmetic
CS 3343: Analysis of Algorithms
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Number Theory (Chapter 7)
CSE 326: Data Structures: Midterm Review
Complexity Present sorting methods. Binary search. Other measures.
Lecture 20 Guest lecturer: Neal Gupta
Data Structures Review Session
CSE 373 Data Structures Lecture 5
Cryptography Lecture 16.
Presentation transcript:

MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm

MA/CSSE 473 Day 05 HW 2 due tonight, 3 is due Monday Student Questions Asymptotic Analysis example: summation Review topics I don’t plan to cover in class Continue Algorithm Overview/Review –Integer Primality Testing and Factoring –Modular Arithmetic intro –Euclid’s Algorithm

MA/CSSE 473 Day 05 HW 2 due tonight, 3 is due Monday Student Questions Asymptotic Analysis example: summation Continue Algorithm Overview/Review –Integer Primality Testing and Factoring –Modular Arithmetic intro Address the issue in my from Tuesday evening: Some possible misunderstanding about my disclaimer Was not intended to be funny, as the limerick was. It was not my opinion, it was just a bunch of facts copied from a NIH web page (four years ago I think) disorders/college-drinkinghttp:// disorders/college-drinking

I don’t really like the term “date rape”. –Rape is rape, and it is a horrendous crime. It is all about the perpetrator, not the victim. –In my opinion, the perp. should have a part of his anatomy cut off, or something worse. The impact on the victim is greater than anyone who has not experienced it can imagine. Nothing that the victim does can legitimize any kind of unwanted sexual advance. Anyone who implies that it is the victim’s fault is just plain wrong! –But so many people believe this, that I can see how someone might interpretthe NIH statement as a “blame the victim” statement. This is a very serious and emotional issue. –So I again apologize for including that in the disclaimer. Anyone who won’t take a single “no” at face value and respect it is evil, IMHO. Unfortunately such evil people exists, and unfortunately the people they choose as victims are often people whom they know, people who would never suspect them of being capable of something so horrendous. IMHO, the NIH web page was simply stating that alcohol is often involved in rape and other crimes. It can embolden the perp. And impair the victim’s extrication ability. If anyone here is victim of rape or anyother kind of violence, my heart goes out to you. As you struggle to find healing, don’t listen to anyone (including yourself) who tells you that you are at fault or that you in any way less of a person because something happened to you that was totally beyond your control.

Asymptotic Analysis Example Find a simple big-Theta expression (as a function of n) for the following sum –when 0 < c < 1 –when c = 1 –when c > 1 f(n) = 1 + c + c 2 + c 3 + … + c n

REVIEW THREAD Quick look at review topics in textbook

Textbook Topics I Won't Cover in Class Chapter 1 topics that I will not discuss in detail unless you have questions. They should be review For some of them, there will be review problems in the homework –Sieve of Eratosthenes (all primes less than n) –Algorithm Specification, Design, Proof, Coding –Problem types : sorting, searching, string processing, graph problems, combinatorial problems, geometric problems, numerical problems –Data Structures: ArrayLists, LinkedLists, trees, search trees, sets, dictionaries,

Textbook Topics I Won't Cover* Chapter 2 –Empirical analysis of algorithms should be review –I believe that we have covered everything else in the chapter except amortized algorithms and recurrence relations –We will discuss amortized algorithms –Recurrence relations are covered in CSSE 230 and MA 375. We'll review particular types as we encounter them. *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 3 - Review –Bubble sort, selection sort, and their analysis –Sequential search and simple string matching *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 4 - Review –Mergesort, quicksort, and their analysis –Binary search –Binary Tree Traversal Orders (pre, post, in, level) *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 5 - Review –Insertion Sort and its analysis –Search, insertion, delete in Binary Tree –AVL tree insertion and rebalance *Unless you ask me to

Efficient Fibonacci Algorithm? Let X be the matrix Then also How many additions and multiplications of numbers are necessary to multiply two 2x2 matrices? If n = 2 k, how many matrix multiplications does it take to compute X n ? –O(log n), it seems. But there is a catch!

Reconsider our Fibonacci algorithms Hidden because not ready for prime time yet. Refine T(n) calculations, (the time for computing the n th Fibonacci number) for each of our three algorithms –Recursive (fib1) We originally had T(n)  Ѳ(F(n)) ≈ Ѳ( n ) We assumed that addition was constant time. Since each addition is Ѳ(n), the whole thing is Ѳ(n∙F(n)) –Array (fib2) We originally had T(n)  Ѳ(n), because of n additions. Since each addition is Ѳ(n), the whole thing is Ѳ(n 2 ) –Matrix multiplication approach (fib3) We saw that Ѳ(log n) 2x2 matrix multiplications give us F n. Let M(k) be the time required to multiply two k-bit numbers. M(k)  Ѳ(k a ) for some a with 1 ≤ a ≤ 2. It's easy to see that T(n)  O(Ml(n) log n) Can we show that T(n)  O(M(n)) ? –Do it for a = 2 and a = log 2 (3) –If the multiplication of numbers is better than O(n 2 ), so is finding the n th Fibonacci number.

ARITHMETIC THREAD Integer Division Modular arithmetic Euclid's Algorithm Heading toward Primality Testing

FACTORING and PRIMALITY Two important problems –FACTORING: Given a number N, express it as a product of its prime factors –PRIMALITY: Given a number N, determine whether it is prime Where we will go with this eventually –Factoring is hard The best algorithms known so far require time that is exponential in the number of bits of N –Primality testing is comparitively easy –A strange disparity for these closely-related problems –Exploited by cryptographic algorithms More on these problems later –First, more math and computational background…

Recap: Arithmetic Run-times For operations on two k-bit numbers: Addition: Ѳ(k) Multiplication: –Standard algorithm: Ѳ(k 2 ) –"Gauss-enhanced": Ѳ(k 1.59 ), but with a lot of overhead. Division (We won't ponder it in detail, but see next slide): Ѳ(k 2 )

Algorithm for Integer Division Let's work through divide(19, 4). Analysis?

Modular arithmetic definitions x modulo N is the remainder when x is divided by N. I.e., –If x = qN + r, where 0 ≤ r < N ( q and r are unique! ), –then x modulo N is equal to r. x and y are congruent modulo N, which is written as x  y (mod N), if and only if N divides (x-y). –i.e., there is an integer k such that x-y = kN. –In a context like this, a divides b means "divides with no remainder", i.e. "a is a factor of b." Example: 253  13 (mod 60)

Modular arithmetic properties Substitution rule – If x  x' (mod N) and y  y' (mod N), then x + y  x' + y' (mod N), and xy  x'y' (mod N) Associativity – x + (y + z)  (x + y) + z (mod N) Commutativity – xy  yx (mod N) Distributivity – x(y+z)  xy +yz (mod N)

Modular Addition and Multiplication To add two integers x and y modulo N (where k =  log N  (the number of bits in N), begin with regular addition. –x and y are in the range_____, so x + y is in range _______ –If the sum is greater than N-1, subtract N. –Run time is Ѳ ( ) To multiply x and y modulo N, begin with regular multiplication, which is quadratic in k. –The result is in range ______ and has at most ____ bits. –Compute the remainder when dividing by N, quadratic time. So entire operation is Ѳ( )

Modular Addition and Multiplication To add two integers x and y modulo N (where k =  log N , begin with regular addition. –x and y are in the range 0 to N-1, so x + y is in range 0 to 2N-1 –If the sum is greater than N-1, subtract N. –Run time is Ѳ (k ) To multiply x and y, begin with regular multiplication, which is quadratic in n. –The result is in range 0 to (N-1) 2 and has at most 2k bits. –Then compute the remainder when dividing by N, quadratic time in k. So entire operation is Ѳ(k 2 )

Modular Exponentiation In some cryptosystems, we need to compute x y modulo N, where all three numbers are several hundred bits long. Can it be done quickly? Can we simply take x y and then figure out the remainder modulo N? Suppose x and y are only 20 bits long. –x y is at least (2 19 ) (2 19 ), which is about 10 million bits long. –Imagine how big it will be if y is a 500-bit number! To save space, we could repeatedly multiply by x, taking the remainder modulo N each time. If y is 500 bits, then there would be bit multiplications. This algorithm is exponential in the length of y. Ouch!

Modular Exponentiation Algorithm Let n be the maximum number of bits in x, y, or N The algorithm requires at most ___ recursive calls Each call is Ѳ( ) So the overall algorithm is Ѳ( )

Modular Exponentiation Algorithm Let n be the maximum number of bits in x, y, or N The algorithm requires at most n recursive calls Each call is Ѳ(n 2 ) So the overall algorithm is Ѳ(n 3 )