CS 2210 Discrete Structures Advanced Counting

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

22C:19 Discrete Structures Advanced Counting Spring 2014 Sukumar Ghosh.
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
CS 2210 (22C:19) Discrete Structures Advanced Counting
April 9, 2015Applied Discrete Mathematics Week 9: Relations 1 Solving Recurrence Relations Another Example: Give an explicit formula for the Fibonacci.
Recurrences. What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the.
Part 5. Computational Complexity (3)
Recursion.
Analysis of Recursive Algorithms
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Analysis of Recursive Algorithms October 29, 2014
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
Jessie Zhao Course page: 1.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Chap. 7 (c) , Michael P. Frank1 Chapter 7: Advanced Counting Techniques.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
14.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo –Divide & conquer –Master’s method.
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Module #17: Recurrence Relations Rosen 5 th ed., §
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
CHAPTER TWO RECURRENCE RELATION
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Recurrence Relations. Outline Recurrence relationsSolving recurrence relationsRecurrence and Divide-and-conquer algorithmsGenerating functions
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
Advanced Counting Techniques
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
CSG523/ Desain dan Analisis Algoritma
CSG523/ Desain dan Analisis Algoritma
CMSC Discrete Structures
Analysis of Algorithms
Modeling with Recurrence Relations
Applied Discrete Mathematics Week 11: Relations
Introduction to Recurrence Relations
CS 3343: Analysis of Algorithms
UNIT-6 Recurrence Relations
Module #17: Recurrence Relations
演算法概論 Introduction to Algorithms
T(n) = aT(n/b) + cn = a(aT(n/b/b) + cn/b) + cn 2
Module #17: Recurrence Relations
Recursion and Recurrence Relations
Divide and Conquer Algorithms Part I
CMSC Discrete Structures
Solving Recurrence Relations
Applied Discrete Mathematics Week 7: Computation
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Chapter 7 Advanced Counting Techniques
Recurrence Relations.
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
ICS 253: Discrete Structures I
Presentation transcript:

CS 2210 Discrete Structures Advanced Counting Fall 2018 Sukumar Ghosh

Compound Interest A person deposits $10,000 in a savings account that yields 10% interest annually. How much will be there in the account after 30 years? Let Pn = account balance after n years. Then Pn = Pn-1 + 0.10 Pn-1 = 1.1Pn-1 Note that the definition is recursive. What is the solution Pn? Pn = Pn-1 + 0.10 Pn-1 = 1.1Pn-1 is a recurrence relation By “solving” this, we get the non-recursive version of it.

Recurrence Relation Recursively defined sequences are also known as recurrence relations. The actual sequence is a solution of the recurrence relations. Consider the recurrence relation: an+1 = 2an (n > 0) [Given a1=1] The solution is: an = 2n-1 (The sequence is 1, 2, 4, 8, …) So, a30 = 229 Given any recurrence relation, can we “solve” it? Which are the ones that can be solved easily?

More examples of Recurrence Relations Fibonacci sequence: an = an-1 + an-2 (n > 2) [Given a1 = 1, a2 = 1] What is the formula for an? 2. How many bit strings of length n that do not have two consecutive 0s. For n=1, the strings are 0 and 1 For n=2, the strings are 01, 10, 11 For n=3, the strings are 011, 111, 101, 010, 110 Do you see a pattern here?

Example of Recurrence Relations Let an be the number of bit strings of length n that do not have two consecutive 0’s. This can be represented as an = an-1 + an-2 (why?) [bit string of length (n-1) without a 00 anywhere] 1 (an-1) and [bit string of length (n-2) without a 00 anywhere] 1 0 (an-2) an = an-1 + an-2 is a recurrence relation. Given this, can you find an?

Tower of Hanoi Transfer these disks from one peg to another. However, at no time, a larger disk should be placed on a disk of smaller size. Start with 64 disks. When you have finished transferring them one peg to another, the world will end.

Can you solve this and compute H64? (H1 = 1) Tower of Hanoi Let, Hn = number of moves to transfer n disks. Then Hn = 2Hn-1 +1 (why?) Can you solve this and compute H64? (H1 = 1)

Solving Linear Homogeneous Recurrence Relations A linear recurrence relation is of the form an = c1.an-1 + c2. an-2 + c3. an-3 + …+ ck. an-k (here c1, c2, …, cn are constants) Its solution is of the form an = rn (where r is a constant) if and only if r is a solution of rn = c1.rn-1 + c2. rn-2 + c3. rn-3 + …+ ck. rn-k This equation is known as the characteristic equation.

Example 1 Solve: an = an-1 + 2 an-2 (Given that a0 = 2 and a1 = 7) Its solution is of the “form” an = rn The characteristic equation is: r2 = r + 2, i.e. r2 - r - 2 = 0. It has two roots r = 2, and r = -1 The sequence {an} is a solution to this recurrence relation iff an = α1 2n + α2 (-1)n a0 = 2 = α1 + α2 a1 = 7 = α1. 2 + α2.(-1) This leads to α1= 3, and α2 = -1 So, the solution is an = 3. 2n - (-1)n

Example 2: Fibonacci sequence Solve: fn = fn-1 + fn-2 (Given that f0 = 0 and f1 = 1) Its solution is of the form fn = rn The characteristic equation is: r2 - r - 1 = 0. It has two roots r = ½(1 + √5) and ½(1 - √5) The sequence {an} is a solution to this recurrence relation iff fn = α1 (½(1 + √5))n + α2 (½(1 - √5))n (Now, compute α1 and α2 from the initial conditions): α1 = 1/√5 and α2 = -1/√5 The final solution is fn = 1/√5. (½(1 + √5))n - 1/√5.(½(1 - √5))n 

Example 3: Case of equal roots If the characteristic equation has only one root r0 (*), then the solution will be an = α1 r0n + α2 .nr0n See the example in the book. 

Example 4: Characteristic equation with complex roots Solve: an = 2.an-1 -2.an-2 (Given that a0 = 0 and a1 = 2) The characteristic equation is: r2 - 2r + 2 = 0. It has two roots (1 + i) and (1 - i) The sequence {an} is a solution to this recurrence relation iff an = α1 (1+i)n + α2 (1-i)n (Now, compute α1 and α2 from the initial conditions): α1 = - i and α2 = i The final solution is an = -i.(1+i)n + i.(1-i)n Check if it works!

Divide and Conquer Recurrence Relations Some recursive algorithms divide a problem of size “n” into “b” sub-problems each of size “n/b”, and derive the solution by combining the results from these sub-problems. This is known as the divide-and-conquer approach Example 1. Binary Search: If f(n) comparisons are needed to search an object from a list of size n, then f(n) = f(n/2) + 2 [1 comparison to decide which half of the list to use, and 1 more to check if there are remaining items]

Divide and Conquer Recurrence Relations Example 2: Finding the maximum and minimum of a sequence f(n) = 2.f(n/2) + 2 Example 3. Merge Sort: Divide the list into two sublists, sort each of them and then merge. Here f(n) = 2.f(n/2) + n

Divide and Conquer Recurrence Relations Theorem. The solution to a recurrence relations of the form f(n) = a.f(n/b) + c (here b divides n, a ≥ 1, b >1, and c is a positive real number) is f(n) (if a=1) (if a >1) (See the complete derivation in page 530)

Divide and Conquer Recurrence Relations Proof outline. Given f(n) = a.f(n/b) + c Let n=bk. Then f(n) = a.[a.f(n/b2)+c] + c = a.[a.[a.f(n/b3)+c]+c]+ c and so on … = ak. f(n/bk) + c.(ak-1+ak-2+…+1) … (1) = ak.f(n/bk) + c.(ak-1)/(a-1) = ak.f(1) + c.(ak-1)/(a-1) … (2)

Divide and Conquer Recurrence Relations Proof outline. Given f(n) = a.f(n/b) + c When a=1, f(n) = f(1) + c.k (from 1) Note that n=bk, k = logbn, So f(n) = f(1) + c. logbn [Thus f(n) = O(log n)] When a>1, f(n) = ak.[f(1) + c/(a-1)] + c/(a-1) [ ]

Divide and Conquer Recurrence Relations What if n ≠ bk? The result still holds. Assume that bk < n <bk+1. So, f(n) < f(bk+1) f(bk+1) = f(1) + c.(k+1) = [f(1) + c] + c.k = [f(1) + c] + c.logbn Therefore, f(n) is O(log n)

Divide and Conquer Recurrence Relations Apply to binary search f(n) = f(n/2) + 2 The complexity of binary search f(n) (since a=1) What about finding the maximum or minimum of a sequence? f(n) = 2f(n/2) + 2 So, the complexity is f(n)

Master Theorem Note that there are four parameter: a, b, c, d