Prepared by John Reif, Ph.D.

Slides:



Advertisements
Similar presentations
CPSC 411 Design and Analysis of Algorithms Set 3: Divide and Conquer Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 3 1.
Advertisements

Number Theory Algorithms and Cryptography Algorithms Prepared by John Reif, Ph.D. Analysis of Algorithms.
A simple example finding the maximum of a set S of n numbers.
Recursive Definitions and Structural Induction
More on Divide and Conquer. The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving.
Introduction to Algorithms Jiafen Liu Sept
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
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))”
Divide-and-Conquer 7 2  9 4   2   4   7
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
Analysis of Algorithms
Project 2 due … Project 2 due … Project 2 Project 2.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Advanced Algebraic Algorithms on Integers and Polynomials Prepared by John Reif, Ph.D. Analysis of Algorithms.
INTRODUCTION. What is an algorithm? What is a Problem?
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Mathematical Background and Linked Lists. 2 Iterative Algorithm for Sum Find the sum of the first n integers stored in an array v : sum (v[], n) temp_sum.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
The Fast Fourier Transform and Applications to Multiplication
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
1 Chapter 4-2 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
7.3 Divide-and-Conquer Algorithms and Recurrence Relations If f(n) represents the number of operations required to solve the problem of size n, it follow.
ADA: 4.5. Matrix Mult.1 Objective o an extra divide and conquer example, based on a question in class Algorithm Design and Analysis (ADA) ,
CS 615: Design & Analysis of Algorithms Chapter 2: Efficiency of Algorithms.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Asymptotics and Recurrence Equations Prepared by John Reif, Ph.D. Analysis of Algorithms.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Prepared by John Reif, Ph.D. Analysis of Algorithms.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
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 05 More induction Factors and Primes Recursive division algorithm.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
1 Proofs by Counterexample & Contradiction There are several ways to prove a theorem:  Counterexample: By providing an example of in which the theorem.
Recursive Definitions
Introduction to Algorithms: Divide-n-Conquer Algorithms
Analysis of Algorithms
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull
Foundations of Algorithm 유관우
Introduction Algorithms Order Analysis of Algorithm
CS 3343: Analysis of Algorithms
Chapter 4: Divide and Conquer
Introduction to the Design and Analysis of Algorithms
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Chapter 4 Divide-and-Conquer
Discrete Structures for Computer Science
CSCE 411 Design and Analysis of Algorithms
Chapter 2: Getting Started
Programming application CC213
Ch 4: Recurrences Ming-Te Chi
Applied Discrete Mathematics Week 9: Integer Properties
Introduction to Algorithms
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Algorithm Analysis, Asymptotic notations CISC4080 CIS, Fordham Univ.
Divide and Conquer Neil Tang 4/24/2008
Lecture 30 CSE 331 Nov 12, 2012.
Divide-and-Conquer 7 2  9 4   2   4   7
Presentation transcript:

Prepared by John Reif, Ph.D. Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Analysis of Algorithms Prepared by John Reif, Ph.D.

Readings Main Reading Selection: CLR, Chapter 1

Goal Devise Algorithms to solve problems on a TI calculator assume each step (a multiplication, addition, or control branch) takes 1 m sec = 10-6 sec on 16 bit words

Time Efficiency

Fibonocci Sequence 0, 1, 1, 2, 3, 5, 8, 13… Recursive Definition Fn = if n < 1 then n else Fn-1 + Fn-2 Problem Compute Fn for n=109 fast.

Fibonacci Growth Can show as n  ∞ Golden ratio So Fn ~ .45 ∙ 2 .7n is .7n bit number grows exponentially!

Obvious Method n if n < 1 Fn = Fn-1 + Fn-2 if n > 1 > .01 n2 steps > 1016 m sec for n = 109 = 1010 sec ~ 317 years! Fn-1 + Fn-2 if n > 1

Wanted! An efficient algorithm for Fn Weapons: Special properties of computational problems = combinatorics (in this case)

Theorem: Proof by Induction Basis Step Holds by definition for n=1 Inductive Step Assume holds for some n>0

Inductive Step

Powering Trick 1 1 1 0 Fix M = To compute Mn when n is a power of 2 1 1 1 0 Fix M = To compute Mn when n is a power of 2 For i=1 to log n do

General Case of Powering Decompose n = 2 j1 + 2 j2 + ... + 2 jk as sum of powers of 2 Example Compute

Algorithm

Bounding Mults = 2 log n matrix products on symmetric matrices of size 2 x 2 Each matrix product costs 6 integer mults Total Cost = 12 (log n) integer mults > 360 for n = 109 integer mults

Time Analysis Fn ~ .45 2 .7n So Fn is m = .7n bit integer New method to compute Fn requires multiplying m bit number BUT Grammar School Method for Mult takes m2 bool ops = m2/16 steps ~ 1016 steps for n = 109 ~ 1016 msec ~ 1010 seconds ~ 317 years!

Fast Multiplication aL aR bL bR of m bit integers a,b by “Divide and Conquer” seems to take 4 multiplications, but… aL aR bL bR

3 Mult Trick

Recursive Mult Algorithm Cost

Schonhage-Strassen Integer Multiplication Algorithm This is feasible to compute!

Improved Algorithm Computed Fn for n = 109 using 360 = 12 log n integer mults each taking ~ 3 days Total time to compute Fn ~ 3 years with 1 msec/step

How Did We Get Even More Speed-Up? New trick a 2 log n mult algorithm (rather than n adds) Old Trick use known efficient algorithms for integer multiplication (rather than Grammar School mult) Also used careful analysis of efficiency of algorithms to compare methods

Problem (to be pondered later…) How fast can 109 integers be sorted? What algorithms would be used?

Prepared by John Reif, Ph.D. Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Analysis of Algorithms Prepared by John Reif, Ph.D.