MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.

Slides:



Advertisements
Similar presentations
Lecture 2 Based on Chapter 1, Weiss. Mathematical Foundation Series and summation: ……. N = N(N+1)/2 (arithmetic series) 1 + r+ r 2 + r 3 +………r.
Advertisements

MATH 224 – Discrete Mathematics
A simple example finding the maximum of a set S of n numbers.
MA/CSSE 473 Day 13 Divide and Conquer Closest Points Convex Hull Answer Quiz Question 1.
Number Theory and Cryptography
DIVIDE AND CONQUER. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
Introduction to Algorithms Jiafen Liu Sept
© Love Ekenberg The Algorithm Concept, Big O Notation, and Program Verification Love Ekenberg.
CSC 3323 Notes – Recurrence Relations Algorithm Analysis.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Chapter 4: Solution of recurrence relationships
The Design and Analysis of Algorithms
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Design and Analysis of Algorithms
Arithmetic.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
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))”
Sequences and Series (T) Students will know the form of an Arithmetic sequence.  Arithmetic Sequence: There exists a common difference (d) between each.
CS Algorithm Analysis1 Algorithm Analysis - CS 312 Professor Tony Martinez.
Divide-and-Conquer 7 2  9 4   2   4   7
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
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.
Project 2 due … Project 2 due … Project 2 Project 2.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data Depends.
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
Sequences and Summations
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
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?
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Prepared by John Reif, Ph.D. Analysis of Algorithms.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
MA/CSSE 473 Day 30 B Trees Dynamic Programming Binomial Coefficients Warshall's algorithm No in-class quiz today Student questions?
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
Chapter 4: Solution of recurrence relationships Techniques: Substitution: proof by induction Tree analysis: graphical representation Master theorem: Recipe.
MA/CSSE 473 Day 04 Multiplication runtime Multiplication based on Gauss formula Mathematical induction review.
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)
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 16.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
MA/CSSE 473 Day 06 DivisionPrimes Modular Arithmetic.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
1 ADT Implementation: Recursion, Algorithm Analysis Chapter 10.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Recursion,
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 04 Multiplication runtime
Prepared by John Reif, Ph.D.
Introduction to Algorithms: Divide-n-Conquer Algorithms
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
The Design and Analysis of Algorithms
MA/CSSE 473 Day 16 Answers to your questions Divide and Conquer
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Algorithms with numbers (1) CISC4080, Computer Algorithms
Mathematical Induction Recursion
CSCE 411 Design and Analysis of Algorithms
Applied Discrete Mathematics Week 9: Integer Properties
Recursion.
Presentation transcript:

MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis

Leftovers Algorithm definition: –Sequence of instructions –For solving a problem –Unambiguous (including order) –Can depend on input –Terminates in a finite amount of time Session #  day of week algorithm

Student questions on … Syllabus? Course procedures, policies, or resources? Course materials? Homework assignments? Anything else? notation: lg n means log 2 n Also, log n without a specified base will usually mean log 2 n

Levitin Algorithm picture

Algorithm design Process

Interlude What we become depends on what we read after all of the professors have finished with us. The greatest university of all is a collection of books. - Thomas CarlyleThomas Carlyle

Review: The Master Theorem The Master Theorem for Divide and Conquer recurrence relations: Consider the recurrence T(n) = aT(n/b) +f(n), T(1)=c, where f(n) = Ѳ(n k ) and k≥0, The solution is –Ѳ(n k )if a < b k –Ѳ(n k log n)if a = b k –Ѳ(n log b a )if a > b k For details, see Levitin pages [ ] or Weiss section Grimaldi's Theorem 10.1 is a special case of the Master Theorem. We will use this theorem often. You should review its proof soon (Weiss's proof is a bit easier than Levitin's). Note that page numbers in brackets refer to Levitin 2 nd edition

Arithmetic algorithms For the next few days: –Reading: mostly review from CSSE 230 and DISCO –In-class: Some review, but mainly arithmetic algorithms Examples: Fibonacci numbers, addition, multiplication, exponentiation, modular arithmetic, Euclid’s algorithm, extended Euclid. –Lots of problems to do –some over review material –Some over arithmetic algorithms.

Fibonacci Numbers F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) Sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … Straightforward recursive algorithm: Correctness is obvious. Why?

Analysis of the Recursive Algorithm What do we count? –For simplicity, we count basic computer operations Let T(n) be the number of operations required to compute F(n). T(0) = 1, T(1) = 2, T(n) = T(n-1) + T(n-2) + 3 What can we conclude about the relationship between T(n) and F(n)? How bad is that? How long to compute F(200) on an exaflop machine (10^18 operations per second)? –

A Polynomial-time algorithm? Correctness is obvious because it again directly implements the Fibonacci definition. Analysis? Now (if we have enough space) we can quickly compute F(14000)

A more efficient algorithm? Let X be the matrix Then also How many additions and multiplications of numbers are needed to compute the product of two 2x2 matrices? If n = 2 k, how many matrix multiplications does it take to compute X n ? –What if n is not a power of 2? –Implement it with a partner (details on next slide) –Then we will analyze it But there is a catch!

identity_matrix = [[1,0],[0,1]] x = [[0,1],[1,1]] def matrix_multiply(a, b): return [[a[0][0]*b[0][0] + a[0][1]*b[1][0], a[0][0]*b[0][1] + a[0][1]*b[1][1]], [a[1][0]*b[0][0] + a[1][1]*b[1][0], a[1][0]*b[0][1] + a[1][1]*b[1][1]]] def matrix_power(m, n): #efficiently calculate m n result = identity_matrix # Fill in the details return result def fib (n) : return matrix_power(x, n)[0][1] # Test code print ([fib(i) for i in range(11)])

Why so complicated? Why not just use the formula that you probably proved by induction in CSSE 230* to calculate F(N)? *See Weiss, exercise 7.8 For review, this proof is part of HW1.

Are addition and multiplication constant-time operations? We take a closer look at the "basic operations" Addition first: At most, how many digits can there be in the sum of three one-digit decimal numbers? Is the same result true in binary? Add two 6-bit positive integers (53+35): Carry: So adding two k-bit integers is Θ( ) time. The catch! (35) (53) (88)

Multiplication of Two k-bit Integers Example: multiply 13 by x (1101 times 1) (1101 times 1, shifted once) (1101 times 1, shifted twice) (1101 times 1, shifted thrice) (binary 143) There are k rows of 2 k bits to add, so we do an  ( k ) operation k times, thus the whole multiplication is  ( ) ? Can we do better?