Algoritmi di Bioinformatica. Computational efficiency I

Similar documents
Fibonacci Sequence. January 19, 2014

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

The Fibonacci Sequence

Recurrences COMP 215

When is a number Fibonacci?

Fundamental Algorithms

Partha Sarathi Mandal

Chapter 8: Recursion. March 10, 2008

Fundamental Algorithms

Recursion and Induction

Data Structure Lecture#4: Mathematical Preliminaries U Kang Seoul National University

Data Structure Lecture#4: Mathematical Preliminaries U Kang Seoul National University

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Lecture 8 : Structural Induction DRAFT

Algorithm efficiency analysis

Chapter 5: Sequences, Mathematic Induction, and Recursion

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Great Theoretical Ideas in Computer Science

ODD FIBBINARY NUMBERS AND THE GOLDEN RATIO

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

Section 11.1: Sequences

MATH 402 : 2017 page 1 of 6

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Design and Analysis of Algorithms Department of Mathematics MA21007/Assignment-2/Due: 18 Aug.

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

The Fibonacci Sequence

Generalization of Fibonacci sequence

Solving Recurrences. Lecture 23 CS2110 Fall 2011

Recursion: Introduction and Correctness

Page references correspond to locations of Extra Examples icons in the textbook.

Problem One: Order Relations i. What three properties does a binary relation have to have to be a partial order?

IS 709/809: Computational Methods for IS Research. Math Review: Algorithm Analysis

Great Theoretical Ideas in Computer Science

Mathematical Background. Unsigned binary numbers. Powers of 2. Logs and exponents. Mathematical Background. Today, we will review:

7. The Recursion Theorem

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n

CSC236H Lecture 2. Ilir Dema. September 19, 2018

Sum of Squares. Defining Functions. Closed-Form Expression for SQ(n)

Example. How to Guess What to Prove

Recursion. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Fall 2007

Advanced Counting Techniques. Chapter 8

Problem Set 1 Solutions

Why do we need math in a data structures course?

Lecture 8: Phyllotaxis, the golden ratio and the Fibonacci sequence

Data Structures and Algorithms Chapter 3

Chapter 2: Time Series Modelling. Chapter 3: Discrete Models. Notes. Notes. Intro to the Topic Time Series Discrete Models Growth and Decay

Introduction to Divide and Conquer

Mathematical Induction. Rosen Chapter 4.1,4.2 (6 th edition) Rosen Ch. 5.1, 5.2 (7 th edition)

Computer Algorithms CISC4080 CIS, Fordham Univ. Outline. Last class. Instructor: X. Zhang Lecture 2

Computer Algorithms CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Lecture 2

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 3

ICS141: Discrete Mathematics for Computer Science I

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 14. Recursive algorithm

CMSC250 Homework 9 Due: Wednesday, December 3, Question: Total Points: Score:

Fibonacci (Leonardo Pisano) ? Statue in Pisa Italy FIBONACCI NUMBERS GOLDEN RATIO, RECURRENCES

Math Circles: Population Models

7. The Recursion Theorem

CSI Mathematical Induction. Many statements assert that a property of the form P(n) is true for all integers n.

Algorithm Analysis, Asymptotic notations CISC4080 CIS, Fordham Univ. Instructor: X. Zhang

CSC236 Week 3. Larry Zhang

3 Finite continued fractions

Induction. Induction. Induction. Induction. Induction. Induction 2/22/2018

Lecture 12 : Recurrences DRAFT

7. The Recursion Theorem

Fibonacci äÿà5ÿ Topological properties of Fibonacci network

CS173 Running Time and Big-O. Tandy Warnow

Week 7 Solution. The two implementations are 1. Approach 1. int fib(int n) { if (n <= 1) return n; return fib(n 1) + fib(n 2); } 2.

1 Introduction (January 21)

Fall 2017 November 10, Written Homework 5

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Fibonacci (Leonardo Pisano) ? Statue in Pisa Italy FIBONACCI NUMBERS AND RECURRENCES

Discrete Math, Spring Solutions to Problems V

CS1800: Strong Induction. Professor Kevin Gold

Fibonacci Numbers. November 7, Fibonacci's Task: Figure out how many pairs of rabbits there will be at the end of one year, following rules.

DYNAMICAL SYSTEMS

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

CS1800: Mathematical Induction. Professor Kevin Gold

Multi-threading model

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 1: Introduction

Proof Techniques (Review of Math 271)

How many hours would you estimate that you spent on this assignment?

Show Your Work! Point values are in square brackets. There are 35 points possible. Some facts about sets are on the last page.

Induction and Recursion

= 1 when k = 0 or k = n. Otherwise, Fact 4.5 (page 98) says. n(n 1)(n 2) (n k + 3)(n k + 2)(n k + 1) (n k + 1)(n k + 2)(n k + 3) (n 2)(n 1) n

Cpt S 223. School of EECS, WSU

Advanced Counting Techniques

Data Structures and Algorithms

Administrivia. COMP9020 Lecture 7 Session 2, 2017 Induction and Recursion. Lecture 6 recap. Lecture 6 recap

INF2220: algorithms and data structures Series 1

Rational Expressions and Radicals

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 3

Semantic Metatheory of SL: Mathematical Induction

1. Problem I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way.

Methods for solving recurrences

CSCI Honor seminar in algorithms Homework 2 Solution

Advanced Counting Techniques. 7.1 Recurrence Relations

CS4311 Design and Analysis of Algorithms. Analysis of Union-By-Rank with Path Compression

The well-known Fibonacci sequence is defined by a recurrence. Specifically,letF i denote the ith number. Then, we have:

Problem. Problem Given a dictionary and a word. Which page (if any) contains the given word? 3 / 26

Recurrence Relations

Transcription:

Algoritmi di Bioinformatica Zsuzsanna Lipták Laurea Magistrale Bioinformatica e Biotechnologie Mediche (LM9) a.a. 2014/15, spring term Computational efficiency I

2 / 18

Computational Efficiency As we will see later in more detail, the efficiency of algorithms is measured w.r.t. running time storage space We will make these concepts more concrete later on, but for now want to give some intuition, using an example. 3 / 18

Example: Computation of nth Fibonacci number Fibonacci numbers: model for growth of populations (simplified model) Start with 1 pair of rabbits in a field each pair becomes mature at age of 1 month and mates after gestation period of 1 month, a female gives birth to 1 new pair rabbits never die 1 Definition F (n) = number of pairs of rabbits in field at the beginning of the n th month. 1 This unrealistic assumption simplifies the mathematics; however, it turns out that adding a certain age at which rabbits die does not significantly change the behaviour of the sequence, so it makes sense to simplify. 4 / 18

Computation of nth Fibonacci number month 1: there is 1 pair of rabbits in the field F (1) = 1 month 2: there is still 1 pair of rabbits in the field F (2) = 1 month 3: there is the old pair and 1 new pair F (3) = 1 + 1 = 2 month 4: the 2 pairs from previous month, plus the old pair has had another new pair F (4) = 2 + 1 = 3 month 5: the 3 from previous month, plus the 2 from month 3 have each had a new pair F (5) = 3 + 2 = 5 Recursion for Fibonacci numbers F (1) = F (2) = 1 for n > 2: F (n) = F (n 1) + F (n 2). 5 / 18

Computation of nth Fibonacci number source: Fibonacci numbers and nature (http://www.maths.surrey.ac.uk/hosted-sites/r.knott/fibonacci/fibnat.html). 6 / 18

Computation of nth Fibonacci number The first few terms of the Fibonacci sequence are: n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 F (n) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 n 15 16 17 18 19 20 21 22 23 F (n) 610 987 1 597 2 584 4 181 6 765 10 946 17 711 28 657 7 / 18

Fibonacci numbers in nature 21 spirals left 34 spirals right source: Plant Spiral Exhibit (http://cs.smith.edu/ phyllo/assets/images/expoimages/expotour/index.htm) On these pages it is explained how these plants develop. Very interesting! 8 / 18

Fibonacci numbers in nature 8 spirals left 13 spirals right source: Plant Spiral Exhibit (http://cs.smith.edu/ phyllo/assets/images/expoimages/expotour/index.htm). 9 / 18

Fibonacci numbers in nature 21 spirals left 13 spirals right source: Fibonacci numbers and nature (http://www.maths.surrey.ac.uk/hosted-sites/r.knott/fibonacci/fibnat.html) very nice page! recommended! 10 / 18

Growth of Fibonacci numbers Theorem For n > 6: F (n) > (1.5) n 1. Proof: Note that from n = 3 on, F (n) strictly increases, so for n 4, we have F (n 1) > F (n 2). Therefore, F (n 1) > 1 2 F (n). We prove the theorem by induction: Base: For n = 6, we have F (6) = 8 > 7.59... = (1.5) 5. Step: Now we want to show that F (n + 1) > (1.5) n. By the I.H. (induction hypothesis), we have that F (n) > (1.5) n 1. Since F (n 1) > 0.5F (n), it follows that F (n + 1) = F (n) + F (n 1) > 1.5 F (n) > (1.5) (1.5) n 1 = (1.5) n. 11 / 18

Computation of nth Fibonacci number Algorithm 1 (let s call it fib1) works exactly along the recursive definition: Algorithm fib1(n) 1. if n = 1 or n = 2 2. then return 1 3. else 4. return fib1(n 1) + fib1(n 2) 12 / 18

Computation of nth Fibonacci number Analysis (sketch) Looking at the computation tree, we can see that the tree for computing F (n) has F (n) many leaves (show by induction), where we have a lookup for F (2) or F (1). A binary rooted tree has one fewer internal nodes than leaves (see second part of course, or show by induction), so this tree has F (n) 1 internal nodes, each of which entails an addition. So for computing F (n), we need F (n) lookups and F (n) 1 additions, altogether 2F (n) 1 operations (additions, lookups etc.). The algorithm has exponential running time, since it makes 2F (n) 1, i.e. at least 2 (1.5) n 1 1 steps (operations). 13 / 18

Computation of nth Fibonacci number Algorithm 2 (let s call it fib2) computes every F (k), for k = 1... n, iteratively (one after another), until we get to F (n). Algorithm fib2(n) 1. array of int F [1... n]; 2. F [1] 1; F [2] 1; 3. for k = 3... n 4. do F [k] F [k 1] + F [k 2]; 5. return F [n]; Analysis (sketch) One addition for every k = 1,..., n. Uses an array of integers of length n. The algorithm has linear running time and linear storage space. 14 / 18

Computation of nth Fibonacci number Algorithm 3 (let s call it fib3) computes F (n) iteratively, like Algorithm 2, but using only 3 units of storage space. Algorithm fib3(n) 1. int a, b, c; 2. a 1; b 1; c 1; 3. for k = 3... n 4. do c a + b; 5. a b; b c; 6. return c; Analysis (sketch) Time: same as Algo 2. Uses 3 units of storage (called a, b, and c). The algorithm has linear running time and constant storage space. 15 / 18

Comparison of running times n 1 2 3 4 5 6 7 10 20 30 40 F (n) 1 1 2 3 5 8 13 55 6 765 832 040 102 334 155 fib1 1 1 3 5 9 15 25 109 13 529 1 664 079 204 668 309 fib2 1 2 3 4 5 6 7 10 20 30 40 fib3 1 2 3 4 5 6 7 10 20 30 40 The number of steps each algorithm makes to compute F (n). 16 / 18

Summary We saw 3 different algorithms for the same problem (computing the nth Fibonacci number). They differ greatly in their efficiency: Algo fib1 has exponential running time. Algo fib2 has linear running time and linear storage space. Algo fib3 has linear running time and constanct storage space. We saw on an example computation (during class) that exponential running time is not practicable. 17 / 18

Summary (2) Take-home message There may be more than one way of computing something. It is very important to use efficient algorithms. Efficiency is measured in terms of running time and storage space. Computation time is important for obvious reasons: the faster the algorithm, the more problems we can solve in the same amount of time. In computational biology, inputs are often very large, therefore storage space is at least as important as running time. 18 / 18