CS Asymptotic Notations for Algorithm Analysis Outline

Similar documents
CS Asymptotic Notations for Algorithm Analysis

CS483 Design and Analysis of Algorithms

CS Non-recursive and Recursive Algorithm Analysis

CSC Design and Analysis of Algorithms. Lecture 1

CS Analysis of Recursive Algorithms and Brute Force

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

MTH 346: The Chinese Remainder Theorem

Chuck Garner, Ph.D. May 25, 2009 / Georgia ARML Practice

4 Powers of an Element; Cyclic Groups

All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points.

Rings and modular arithmetic

cse547, math547 DISCRETE MATHEMATICS Professor Anita Wasilewska

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

About complexity. We define the class informally P in the following way:

MATH 433 Applied Algebra Lecture 4: Modular arithmetic (continued). Linear congruences.

MATH 420 FINAL EXAM J. Beachy, 5/7/97

CMPUT 403: Number Theory

CSC 474 Network Security. Outline. GCD and Euclid s Algorithm. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

Discrete Math in Computer Science Solutions to Practice Problems for Midterm 2

Lecture 6: Introducing Complexity

Number Theory Alex X. Liu & Haipeng Dai

Input Decidable Language -- Program Halts on all Input Encoding of Input -- Natural Numbers Encoded in Binary or Decimal, Not Unary

Solution Sheet (i) q = 5, r = 15 (ii) q = 58, r = 15 (iii) q = 3, r = 7 (iv) q = 6, r = (i) gcd (97, 157) = 1 = ,

2301 Assignment 1 Due Friday 19th March, 2 pm

Outline. Some Review: Divisors. Common Divisors. Primes and Factors. b divides a (or b is a divisor of a) if a = mb for some m

Outline. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

cse547, math547 DISCRETE MATHEMATICS Short Review for Final

Homework 3, solutions

Algorithm Efficiency. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University

CS483 Design and Analysis of Algorithms

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Chapter 9 Basic Number Theory for Public Key Cryptography. WANG YANG

Divisibility. Chapter Divisors and Residues

1. multiplication is commutative and associative;

Admin. ! Will post sample questions soon. 1. Choose a bit-length k. 2. Choose two primes p and q which can be represented with at most k bits

An Algorithm for Prime Factorization

Principles of Algorithm Analysis

(a) 14 and 42 (b) 33 and 18 (c) 45 and 108 (d) 24 and 2039, given that 2039 is a prime number

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald)

M381 Number Theory 2004 Page 1

Simultaneous Linear, and Non-linear Congruences

Math Circle Beginners Group February 28, 2016 Euclid and Prime Numbers

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

2 Elementary number theory

1 Overview and revision

Discrete Math, Fourteenth Problem Set (July 18)

Algorithmic number theory. Questions/Complaints About Homework? The division algorithm. Division

CS Data Structures and Algorithm Analysis

Wednesday, February 21. Today we will begin Course Notes Chapter 5 (Number Theory).

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Number Theory. Zachary Friggstad. Programming Club Meeting

About complexity. Number theoretical algorithms

CS250: Discrete Math for Computer Science

The Euclidean Algorithm and Multiplicative Inverses

CMSC Discrete Mathematics SOLUTIONS TO SECOND MIDTERM EXAM November, 2005

Section 19 Integral domains

Name: MAT 444 Test 4 Instructor: Helene Barcelo April 19, 2004

Math 4400 First Midterm Examination September 21, 2012 ANSWER KEY. Please indicate your reasoning and show all work on this exam paper.

WORKSHEET ON NUMBERS, MATH 215 FALL. We start our study of numbers with the integers: N = {1, 2, 3,...}

Number Theory Proof Portfolio

The Chinese Remainder Theorem

Optimisation and Operations Research

COMP239: Mathematics for Computer Science II. Prof. Chadi Assi EV7.635

NOTES ON SIMPLE NUMBER THEORY

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

Chapter 5.1: Induction

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

Module 1: Analyzing the Efficiency of Algorithms

Divisibility in the Fibonacci Numbers. Stefan Erickson Colorado College January 27, 2006

Midterm 3 Review. Terms. Formulas and Rules to Use. Math 1010, Fall 2011 Instructor: Marina Gresham. Odd Root ( n x where n is odd) Exponent

Practice Number Theory Problems

Integers and Division

Lecture 11: Cantor-Zassenhaus Algorithm

An integer p is prime if p > 1 and p has exactly two positive divisors, 1 and p.

2. THE EUCLIDEAN ALGORITHM More ring essentials

Lecture Notes. Advanced Discrete Structures COT S

2.2 Inverses and GCDs

CIS 6930/4930 Computer and Network Security. Topic 4. Cryptographic Hash Functions

Homework #2 solutions Due: June 15, 2012

CS2800 Questions selected for fall 2017

Math 546, Exam 2 Information.

Elementary Number Theory Review. Franz Luef

Direct Proof Divisibility

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

Direct Proof Divisibility

Exam 2 Review Chapters 4-5

CISC-102 Fall 2017 Week 6

Number Theory and the abc Conjecture

Math Circle Beginners Group February 28, 2016 Euclid and Prime Numbers Solutions

Number Theory. Everything else. Misha Lavrov. ARML Practice 10/06/2013

CS483 Design and Analysis of Algorithms

NOTES ON INTEGERS. 1. Integers

Prime Factorization and GCF. In my own words

Proofs of the infinitude of primes

Factoring. there exists some 1 i < j l such that x i x j (mod p). (1) p gcd(x i x j, n).

7.2 Applications of Euler s and Fermat s Theorem.

Mathematical Foundations of Public-Key Cryptography

The Fundamental Theorem of Arithmetic

Fall 2017 Test II review problems

MATH 3330 ABSTRACT ALGEBRA SPRING Definition. A statement is a declarative sentence that is either true or false.

Transcription:

CS483-02 Asymptotic Notations for Algorithm Analysis Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm - 5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483 fall07/ This lecture note is based on Dr. J.M. Lien s lecture notes. CS483 Design and Analysis of Algorithms 1 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 2 Lecture 02, August 30, 2007 Review In last class In last class What is an algorithm? Definition and properties Why we study algorithms? Review Theoretical importance and practical importance There may exist multiple algorithms for the same problem. (Refer to Greatest Common Divisor Problem.) What is an algorithm? Its definition and properties Why we study algorithms? Theoretical importance and practical importance There may exist multiple algorithms for the same problem. (Refer to Greatest Common Divisor Problem.) In this class Given an algorithm, how we analyze it? Is the algorithm correct? What is its running time? (similar for space efficiency analysis) CS483 Design and Analysis of Algorithms 3 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 4 Lecture 02, August 30, 2007

Example: Greatest Common Divisor gcd(m, n) 3 algorithms calculating gcd(m, n). Assumem>n>0. 1. From gcd(m, n) s definition: check each number in decreasing order by 1 starting from min{m, n}. n, n 1,n 2,... 2. From gcd(m, n) s definition and prime numbers definition: gcd(m, n) is the product of all common factors of m and n. List all prime numbers n. (Sieve method) Prime number factorization of m and n. Multiply all the common factors. 3. Euclid s algorithm: gcd(m, n) =gcd(n, m mod n) CS483 Design and Analysis of Algorithms 5 Lecture 02, August 30, 2007 Example: Greatest Common Divisor gcd(m, n) 3 algorithms calculating gcd(m, n). Assume m>n>0. 1. From gcd(m, n) s definition: check each number in decreasing order by 1 since min{m, n}. n, n 1,n 2,... 2. From gcd(m, n) s definition and prime numbers definition: gcd(m, n) is the product of all common factors of m and n. List all prime numbers n. (Sieve method) Prime number factorization of m and n. Multiply all the common factors. 3. Euclid s algorithm: gcd(m, n) =gcd(n, m mod n) Question: Which one runs the fastest? CS483 Design and Analysis of Algorithms 6 Lecture 02, August 30, 2007 Empirical Analysis vs. Theoretical Analysis of Time Efficiency Approach of estimating the running time 1. Select a typical sample of inputs 2. Count actual number of basic executions or record the running time 3. Analyze the collected data CS483 Design and Analysis of Algorithms 7 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 8 Lecture 02, August 30, 2007

Empirical Analysis vs. Theoretical Analysis of Time Efficiency Approach of estimating the running time 1. Select a typical sample of inputs 2. Count actual number of basic executions or record the running time 3. Analyze the collected data Drawbacks Difficult to decide on how many samples/tests are needed to be ne Theoretical Analysis of Time Efficiency Goal Provide a machine independent measurement Common sense The size of input is increased algorithms run longer Hardware/environmental dependent Implementation dependent CS483 Design and Analysis of Algorithms 9 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 10 Lecture 02, August 30, 2007 Theoretical Analysis of Time Efficiency Theoretical Analysis of Time Efficiency Goal Provide a machine independent measurement We are satisfied with this goal. Common sense Input size 1. sort {a 1,a 2,,a n} 2 3 2 a 11 a 1m 2. 6... 4.... 7 6 5 4 b 11 b 1k....... 3 7 5 The size of input is increased algorithms run longer a n1 a nm b m1 b mk Measurement is based on 3. prime(n) input size basic operation order of growth of running time 4. Basic operation The operation that contributes most towards the running time CS483 Design and Analysis of Algorithms 11 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 12 Lecture 02, August 30, 2007

Theoretical Analysis of Time Efficiency Input size Basic operation Running time T (n) where n is the input size T (n) c op C(n), C(n) is the total number of basic operations for input of size n. c op is the time needed to execute one single basic operation. CS483 Design and Analysis of Algorithms 13 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 14 Lecture 02, August 30, 2007 Input size Worst-case, Best-case, Average-case Example: Greatest Common Divisor Basic operation Running time T (n) T (n) c op C(n), For some algorithms efficiency depends on form of input: Worst case: C worst (n) maximum over inputs of size n Best case: C best (n) minimum over inputs of size n Average case: C avg (n) average over inputs of size n Algorithm 0.1: gcd(a, b) Input size: n =min(a, b) Basic operation: a mod i CS483 Design and Analysis of Algorithms 15 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 16 Lecture 02, August 30, 2007

Example: Greatest Common Divisor Example: Greatest Common Divisor Algorithm 0.2: gcd(a, b) Algorithm 0.3: gcd(a, b) Input size: n =min(a, b) Basic operation: a mod i Worst case (worst case analysis provides an upper bound): When es the worst case happen? (a and b are relatively prime) C worst (n) =n Input size: n =min(a, b) Basic operation: a mod i Best case When es the best case happen? (gcd(a, b) =min(a, b)) C best (n) =1 CS483 Design and Analysis of Algorithms 17 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 18 Lecture 02, August 30, 2007 Algorithm 0.4: gcd(a, b) Example: Greatest Common Divisor Input size: n =min(a, b) Basic operation: a mod i Average case Things need to be pay attention to Number of times of the basic operation will be executed on typical * instances * NOT the average of worst and best cases Expected number of basic operations considered as a ranm variable * under some assumption about the probability distribution of all possible inputs Assumptions * Assume that a and b are two ranmly chosen integers * Assume that all integers have the same probability of being chosen hint: The probability that an integer i is a and b s greatest common * divisor is P a,b (i) = 6 π 2 i 2 gcd(a, b) as the integer i such that (i a, b) and x := a/i and y := b/i are co-prime. The probability of two integers sharing a factor i is i 2.The probability that two integers are co-prime is 6/π 2.) CS483 Design and Analysis of Algorithms 19 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 20 Lecture 02, August 30, 2007

Example: Greatest Common Divisor Algorithm 0.5: gcd(a, b) Average case Denote n =min(a, b) C avg (n) = 1 P a,b (n)+2 P a,b (n 1) + + n P a,b (1) = 6 π 2 ( 1 n 2 + 2 (n 1) 2 + + n 1 2 ) When n =10, C avg (10) = 8.583. CS483 Design and Analysis of Algorithms 21 Lecture 02, August 30, 2007 CS483 Design and Analysis of Algorithms 22 Lecture 02, August 30, 2007 Orders of Growth Input size Basic operation Running time T (n) T (n) c op C(n), where n is the input size, C(n) is the total number of basic operations for input of size n, and c op is the time needed to execute one single basic operation. Examples Given that C(n) = 1 2n(n 1), how much the performance will be affected if the input size n is ubled? growth = T (2n) T (n) cop C(2n) c op C(n) = 4n 2 n 1 4 CS483 Design and Analysis of Algorithms 23 Lecture 02, August 30, 2007