Discrete Mathematics: Logic. Discrete Mathematics: Lecture 17. Recurrence

Size: px
Start display at page:

Download "Discrete Mathematics: Logic. Discrete Mathematics: Lecture 17. Recurrence"

Transcription

1 Discrete Mathematics: Logic Discrete Mathematics: Lecture 17. Recurrence

2 greedy algorithm greedy algorithm makes the best choice at each step (locally optimal solution) according to a specified criterion with the hope of finding a global optimum make 67 cents change with quaters(25 cents), dimes(10 cents), nickels(5 cents), and pennies(1 cent), and using the least total number of coins 2 quaters => 50 cents 1 dime => 10 cents 1 nickel => 5 cents 2 cents => 2 cents

3 greedy algorithm procedure change (a1, a2,..., ar: different types of coins, a1 > a2 >... > ak n: positive integer) for i := 1 to k di := 0 { di counts the coins ai used } while n ai di := di + 1 { add a coin ai} n := n - ai {di is the number of the coin ai for i = 1, 2,... k}

4 greedy algorithm make 40 cents change with quaters(25 cents), dimes(10 cents), and pennies(1 cent), and using the least total number of coins 1 quaters => 25 cents 1 dime => 10 cents 1 cents => 5 cents

5 greedy algorithm make 40 cents change with quaters(25 cents), dimes(10 cents), and pennies(1 cent), and using the least total number of coins 1 quaters => 25 cents 1 dime => 10 cents 1 cents => 5 cents 4 dime => 40 cents

6 modeling with recurrence relations Minimum number of changes Input: n denominations of coins V1 (=1) < V2 < V3 <... < Vk problem: use the smallest number of coins to make the amount of money C M(j): minimum number of coins required to make the amount of money j M(j) = min {M(j - vi)} + 1 vi <= j

7 modeling with recurrence relations Input: n denominations of coins V1 (=1) < V2 < V3 <... < Vk change(p) if (p = 0) then return 0 else return 1 + min{ change(p-v1), change(p-v2),..., change(p-vk)}

8 modeling with recurrence relations Input: n denominations of coins V1 (=1) < V2 < V3 <... < Vk change_dp(n) C[0] = 0 for p = 2 to n min = inf for i = 1 to k if (p >= vi && C[p - vi] + 1 < min) min = C[p - vi] + 1 C[p] = min

9 modeling with recurrence relations Scheduling talks with the maximum attendees when we have n talks, we want to maximize the total number of student attendees. T(j): the maximum number of total attendees for an optimal schedule from the first j talks P(j): talk ending latest among talks compatible with talk j that end before talk j the largest integer i, i< j for which ei <= sj wj: the number of students for talk j T(j) = max(wj + T(p(j)), T(j-1))

10 modeling with recurrence relations procedure Maximum Attendees(s1, s2,... sn: start times of talks; e1, e2,...en: end times of talks; w1, w2,..., wn: number of attendees to talks) sort talks by end time and relabel so that e1 e2... en for j := 1 to n if no job i with i < j is compatible with job j p(j) = 0 else p(j) := max{ i i < j and job i is compatible with job j} T(0) := 0 for j := 1 to n T(j) := max(wj + T(p(j)), T(j-1)) return T(n) {T(n) is the maximum number of attendees}

11 linear homogeneous recurrence relation( ) linear homogeneous recurrence relation of degree k with constant coefficients an = c1an-1 + c2an ckan-k, c1, c2,... ck are real numbers and ck 0 Pn = (1.11)Pn-1 : fn = fn-1 + fn-2 : an = an-5 : an = an-1 + an-2 2 : Hn = 2Hn-1 + 1: Bn = nbn-1: linear homogeneous recurrence relation of degree one linear homogeneous recurrence relation of degree two linear homogeneous recurrence relation of degree five not linear not homogeneous does not have constant coefficients

12 linear homogeneous recurrence relation Let an = c1an-1 + c2an ckan-k be a linear homogeneous recurrence relation and bn = c1bn-1 + c2bn ckbn-k be a linear homogeneous recurrence relation pn = an + bn = (c1an-1 + c2an ckan-k ) + (c1bn-1 + c2bn ckbn-k) = c1(an-1 + bn-1) + c1(an-2 + bn-2) +.. c1(an-k + bn-k) = c1pn-1 + c2pn ckpn-k thus, pn is a solution of the recurrence qn = α an = c1(α an-1) + c2 (α an-2) ck (α an-k) = c1qn-1 + c2qn ckqn-k thus, qn is a solution of the recurrence if we find some solutions to a linear homogeneous recurrence, then any linear combination of them will be a solution to the linear homogeneous recurrence.

13 linear homogeneous recurrence relation solving linear homogeneous recurrence relation is to find solutions of the form an = r n for the recurrence relation an = c1an-1 + c2an ckan-k r n = c1r n-1 + c2r n ckr n-k ( = r k - c1r k-1 + c2r k ck-1r - ck = 0 : characteristic equation) the solutions of this equation are called the characteristic roots of the recurrence relation

14 linear homogeneous recurrence relation Theorem consider an = c1an-1 + c2an-2. if characteristic equation r 2 - c1r - c2 = 0 has two distinct roots r1 and r2, the solution to the recurrence relation is an = α1r1 n + α2r2 n if r1 and r2 are roots of r 2 - c1r - c2 = 0, r1 2 = c1r1 + c2, r2 2 = c1r2 + c2 c1an-1 + c2an-2 = c1(α1r1 n-1 + α2r2 n-1 ) + c2(α1r1 n-2 + α2r2 n-2 ) = α1r1 n-2 (c1r1 + c2) + α2r2 n-2 (c1r2 + c2) = α1r1 n-2 r1 2 + α2r2 n-2 r2 2 = α1r1 n + α2r2 n = an

15 linear homogeneous recurrence relation an = an-1 + 2an-2 with a0 = 2 and a1 = 7? r 2 -r -2 = 0 (r - 2)(r + 1) = 0 r = 2, r = -1 an = α12 n + α2(-1) n an = α1r1 n + α2r2 n a0 = α1 + α2 = 2 a1 = α1 2 + α2 (-1) = 7 α1 = 3, α2 = -1, an = 3 2 n - (-1) n

16 linear homogeneous recurrence relation an = an-1 + an-2 with a0 = 0 and a1 = 1 (Fibonacci numbers)? r 2 -r -1 = 0 (1 ± (1+4))/2 an = α1 ((1 + 5)/2) n + α2((1-5)/2) n an = α1r1 n + α2r2 n a0 = α1 + α2 = 0 a1 = α1 ((1 + 5)/2) + α2((1-5)/2) = 1 α1 = 1/ 5, α2 = -1/ 5, an = 1/ 5((1 + 5)/2) n - 1/ 5((1-5)/2) n

17 linear homogeneous recurrence relation Theorem consider an = c1an-1 + c2an-2 if characteristic equation r 2 - c1r - c2 = 0 has only one root r0, the solution to the recurrence relation is an = α1r0 n + α2nr0 n an = 6an-1-9an-2 with initial conditions a0 = 1 and a1 = 6? the only root of r 2-6r + 9 = 0 is r=3 an = α13 n + α2n3 n a0 = α1 = 1 a1 = α2 3 = 6 α2 = 1 an = 3 n + n3 n

18 linear homogeneous recurrence relation consider an = c1an-1 + c2an ckan-k if characteristic equation r k - c1r k ck = 0 has k distinct roots r1, r2,..., rk, the solution to the recurrence relation is an = α1r1 n + α2r2 n αkrk n an = 6an-1-11an-2 + 6an-3 with initial conditions a0 = 2, a1 = 5, and a2 = 15? the roots of r 3-6r r - 6 = (r - 1)(r - 2)(r - 3) are r=1, r=2, and r=3 an = α11 n + α22 n + α33 n a0 = α1 + α2 + α3 = 2 a1 = α1 + α2 2 + α3 3 = 5 a2 = α1 + α2 4 + α3 9 = 15 α1 = 1, α2 = -1, α3 = 2, an = 1 1 n -1 2 n n

19 divide-and-conquer recurrence relations when a recursive algorithm divides a problem of size n into a subproblems, f(n) = a f(n/b) + g(n) n/b: the size of each subproblem g(n): the number of operation in the conquer step

20 recursive binary search procedure binary search(i, j, x: integers, 1 i j n) m := (i+j)/2 if x = am then return m else if (x < am and i < m) then return binary search(i, m-1, x) else if (x > am and j > m) then return binary search(m+1, j, x) else return 0 {i is the start output is the location of x in a1, a2,... an if it appears; otherwise it is 0} f(n) = f(n/2) + 1

21 recursive binary search f(n) = f(n/2) + 1 = (f(n/4) + 1) + 1 = f(n/2 2 ) + 2 = (f(n/8) + 1) + 1 = f(n/2 3 ) + 3 = : = f(n/2 k ) + k = 1 + log n when n = 2 k, k = log n, f(n) = log n

22 merge sort divide conquer

23 merge sort procedure mergesort(l=a1,... an) if n > 1 then m := n/2 L1 := a1, a2,..., am L2 := am+1, am+2,...,an L := merge(mergesort(l1), mergesort(l2)) {L is now sorted into elements in nondecreasing order} procedure merge(l1, L2) L := empty list while L1 and L2 are nonempty remove smaller of first elements of L1 and L2 from its list put it at the right end of L if this removal makes one list empty then remove all elements from the other list and append them to L return L

24 merge sort f(1) = 1 f(n) = 2f(N/2) + N f(n)/n = f(n/2) / (N/2) + 1 f(n/2) / (N/2) = f(n/4) / (N/4) + 1 f(n/4) / (N/4) = f(n/8) / (N/8) + 1 : f(2) / (2) = f(1) / (1) + 1 f(n)/n = f(1)/1 + log N f(n) = N log N + N = O(N log N)

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

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 14. Recursive algorithm Discrete Mathematics: Logic Discrete Mathematics: Lecture 14. Recursive algorithm recursive algorithms a n = a a a a a a a = a a n-1 power (a, n) = a power (a, n-1) basis step: if n = 0, power(a, 0) =

More information

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005 V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the

More information

Recurrence Relations

Recurrence Relations Recurrence Relations Winter 2017 Recurrence Relations Recurrence Relations A recurrence relation for the sequence {a n } is an equation that expresses a n in terms of one or more of the previous terms

More information

CSE 421 Dynamic Programming

CSE 421 Dynamic Programming CSE Dynamic Programming Yin Tat Lee Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs compatible if they don t overlap. Goal: find maximum

More information

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence. Solving Recurrences Recurrences and Recursive Code Many (perhaps most) recursive algorithms fall into one of two categories: tail recursion and divide-andconquer recursion. We would like to develop some

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I 6. DYNAMIC PROGRAMMING I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013

More information

CSC2100B Data Structures Analysis

CSC2100B Data Structures Analysis CSC2100B Data Structures Analysis Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Algorithm An algorithm

More information

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh CS 2210 Discrete Structures Advanced Counting Fall 2017 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

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I 6. DYNAMIC PRORAMMIN I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

CS481: Bioinformatics Algorithms

CS481: Bioinformatics Algorithms CS481: Bioinformatics Algorithms Can Alkan EA224 calkan@cs.bilkent.edu.tr http://www.cs.bilkent.edu.tr/~calkan/teaching/cs481/ Reminder The TA will hold a few recitation sessions for the students from

More information

CSE 21 Mathematics for

CSE 21 Mathematics for CSE 21 Mathematics for Algorithm and System Analysis Motivating Create a recursive formula to specify how many ways to climb an n-stair staircase if each step covers either one or two stairsteps Summer,

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

COMP 555 Bioalgorithms. Fall Lecture 3: Algorithms and Complexity

COMP 555 Bioalgorithms. Fall Lecture 3: Algorithms and Complexity COMP 555 Bioalgorithms Fall 2014 Lecture 3: Algorithms and Complexity Study Chapter 2.1-2.8 Topics Algorithms Correctness Complexity Some algorithm design strategies Exhaustive Greedy Recursion Asymptotic

More information

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions Assignment 4 CSci 3110: Introduction to Algorithms Sample Solutions Question 1 Denote the points by p 1, p 2,..., p n, ordered by increasing x-coordinates. We start with a few observations about the structure

More information

Coin Changing: Give change using the least number of coins. Greedy Method (Chapter 10.1) Attempt to construct an optimal solution in stages.

Coin Changing: Give change using the least number of coins. Greedy Method (Chapter 10.1) Attempt to construct an optimal solution in stages. IV-0 Definitions Optimization Problem: Given an Optimization Function and a set of constraints, find an optimal solution. Optimal Solution: A feasible solution for which the optimization function has the

More information

2. (25%) Suppose you have an array of 1234 records in which only a few are out of order and they are not very far from their correct positions. Which

2. (25%) Suppose you have an array of 1234 records in which only a few are out of order and they are not very far from their correct positions. Which COT 6401 The Analysis of Algorithms Midterm Test Open books and notes Name - SSN - 1. (25%) Suppose that the function F is dened for all power of 2 and is described by the following recurrence equation

More information

Recurrences COMP 215

Recurrences COMP 215 Recurrences COMP 215 Analysis of Iterative Algorithms //return the location of the item matching x, or 0 if //no such item is found. index SequentialSearch(keytype[] S, in, keytype x) { index location

More information

Generating Function Notes , Fall 2005, Prof. Peter Shor

Generating Function Notes , Fall 2005, Prof. Peter Shor Counting Change Generating Function Notes 80, Fall 00, Prof Peter Shor In this lecture, I m going to talk about generating functions We ve already seen an example of generating functions Recall when we

More information

Notes for Recitation 14

Notes for Recitation 14 6.04/18.06J Mathematics for Computer Science October 4, 006 Tom Leighton and Marten van Dijk Notes for Recitation 14 1 The Akra-Bazzi Theorem Theorem 1 (Akra-Bazzi, strong form). Suppose that: is defined

More information

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms 1 Chapter Summary Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms 2 Section 5.1 3 Section Summary Mathematical Induction Examples of

More information

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Divide-and-conquer: Order Statistics. Curs: Fall 2017 Divide-and-conquer: Order Statistics Curs: Fall 2017 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers.

More information

Advanced Counting Techniques. 7.1 Recurrence Relations

Advanced Counting Techniques. 7.1 Recurrence Relations Chapter 7 Advanced Counting Techniques 71 Recurrence Relations We have seen that a recursive definition of a sequence specifies one or more initial terms and a rule for determining subsequent terms from

More information

Dynamic Programming( Weighted Interval Scheduling)

Dynamic Programming( Weighted Interval Scheduling) Dynamic Programming( Weighted Interval Scheduling) 17 November, 2016 Dynamic Programming 1 Dynamic programming algorithms are used for optimization (for example, finding the shortest path between two points,

More information

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence. 1 Recurrences and Recursive Code Solving Recurrences Many (perhaps most) recursive algorithms fall into one of two categories: tail recursion and divide-andconquer recursion. We would like to develop some

More information

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.

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. Week 7 Solution 1.You are given two implementations for finding the nth Fibonacci number(f Fibonacci numbers are defined by F(n = F(n 1 + F(n 2 with F(0 = 0 and F(1 = 1 The two implementations are 1. Approach

More information

Dynamic Programming. Cormen et. al. IV 15

Dynamic Programming. Cormen et. al. IV 15 Dynamic Programming Cormen et. al. IV 5 Dynamic Programming Applications Areas. Bioinformatics. Control theory. Operations research. Some famous dynamic programming algorithms. Unix diff for comparing

More information

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms CompSci 102 Discrete Math for Computer Science Announcements Read for next time Chap. 3.1-3.3 Homework 3 due Tuesday We ll finish Chapter 2 first today February 7, 2012 Prof. Rodger Chap. 3.1 Algorithms

More information

CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure

CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure CSE Weighted Interval Scheduling, Knapsack, RNA Secondary Structure Shayan Oveis haran Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 //8 Fast Integer Division Too (!) Schönhage Strassen algorithm CS 8: Algorithm Design and Analysis Integer division. Given two n-bit (or less) integers s and t, compute quotient q = s / t and remainder

More information

Induction and recursion. Chapter 5

Induction and recursion. Chapter 5 Induction and recursion Chapter 5 Chapter Summary Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms Mathematical Induction Section 5.1

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Chapter 2 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: Room 5326, Engineering Building, Thursday 4:30pm -

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 208 Announcement: Homework 3 due February 5 th at :59PM Final Exam (Tentative): Thursday, May 3 @ 8AM (PHYS 203) Recap: Divide

More information

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3 April 8, 2014 Contents 1 Overview 3 2 Principles of Counting 3 2.1 Pigeon-Hole Principle........................ 3 2.2 Permutations and Combinations.................. 3 2.3 Binomial Coefficients.........................

More information

CSE 202 Dynamic Programming II

CSE 202 Dynamic Programming II CSE 202 Dynamic Programming II Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally,

More information

Advanced Counting Techniques

Advanced Counting Techniques . All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education. Advanced Counting

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

CS173 Running Time and Big-O. Tandy Warnow

CS173 Running Time and Big-O. Tandy Warnow CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review

More information

Induction and Recursion

Induction and Recursion . All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education. Induction and Recursion

More information

Greedy Algorithms My T. UF

Greedy Algorithms My T. UF Introduction to Algorithms Greedy Algorithms @ UF Overview A greedy algorithm always makes the choice that looks best at the moment Make a locally optimal choice in hope of getting a globally optimal solution

More information

Dynamic Programming: Interval Scheduling and Knapsack

Dynamic Programming: Interval Scheduling and Knapsack Dynamic Programming: Interval Scheduling and Knapsack . Weighted Interval Scheduling Weighted Interval Scheduling Weighted interval scheduling problem. Job j starts at s j, finishes at f j, and has weight

More information

Divide-and-Conquer Algorithms and Recurrence Relations. Niloufar Shafiei

Divide-and-Conquer Algorithms and Recurrence Relations. Niloufar Shafiei Divide-and-Conquer Algorithms and Recurrence Relations Niloufar Shafiei Divide-and-conquer algorithms Divide-and-conquer algorithms: 1. Dividing the problem into smaller sub-problems 2. Solving those sub-problems

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 MA008 p.1/37 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/37 Exercise 1 (from LN 2) Asymptotic Notation When constants appear in exponents

More information

CS2223 Algorithms D Term 2009 Exam 3 Solutions

CS2223 Algorithms D Term 2009 Exam 3 Solutions CS2223 Algorithms D Term 2009 Exam 3 Solutions May 4, 2009 By Prof. Carolina Ruiz Dept. of Computer Science WPI PROBLEM 1: Asymptoptic Growth Rates (10 points) Let A and B be two algorithms with runtimes

More information

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

More information

Fundamental Algorithms

Fundamental Algorithms Chapter 2: Sorting, Winter 2018/19 1 Fundamental Algorithms Chapter 2: Sorting Jan Křetínský Winter 2018/19 Chapter 2: Sorting, Winter 2018/19 2 Part I Simple Sorts Chapter 2: Sorting, Winter 2018/19 3

More information

Fundamental Algorithms

Fundamental Algorithms Fundamental Algorithms Chapter 2: Sorting Harald Räcke Winter 2015/16 Chapter 2: Sorting, Winter 2015/16 1 Part I Simple Sorts Chapter 2: Sorting, Winter 2015/16 2 The Sorting Problem Definition Sorting

More information

Dynamic Programming 1

Dynamic Programming 1 Dynamic Programming 1 lgorithmic Paradigms Divide-and-conquer. Break up a problem into two sub-problems, solve each sub-problem independently, and combine solution to sub-problems to form solution to original

More information

Activity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities.

Activity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities. Greedy Algorithm 1 Introduction Similar to dynamic programming. Used for optimization problems. Not always yield an optimal solution. Make choice for the one looks best right now. Make a locally optimal

More information

The Divide-and-Conquer Design Paradigm

The Divide-and-Conquer Design Paradigm CS473- Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm CS473 Lecture 4 1 The Divide-and-Conquer Design Paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems

More information

Advanced Counting Techniques. Chapter 8

Advanced Counting Techniques. Chapter 8 Advanced Counting Techniques Chapter 8 Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence Relations Nonhomogeneous Recurrence Relations Divide-and-Conquer

More information

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n.

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n. 11 Recurrences A recurrence equation or recurrence counts things using recursion. 11.1 Recurrence Equations We start with an example. Example 11.1. Find a recurrence for S(n), the number of subsets of

More information

Lecture 7: Dynamic Programming I: Optimal BSTs

Lecture 7: Dynamic Programming I: Optimal BSTs 5-750: Graduate Algorithms February, 06 Lecture 7: Dynamic Programming I: Optimal BSTs Lecturer: David Witmer Scribes: Ellango Jothimurugesan, Ziqiang Feng Overview The basic idea of dynamic programming

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I lgorithmic paradigms 6. DYNMI PRORMMIN I weighted interval scheduling segmented least squares knapsack problem RN secondary structure reedy. Build up a solution incrementally, myopically optimizing some

More information

Introduction to Algorithms 6.046J/18.401J/SMA5503

Introduction to Algorithms 6.046J/18.401J/SMA5503 Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 3 Prof. Piotr Indyk The divide-and-conquer design paradigm. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali February 19, 2013 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine

More information

Recursion: Introduction and Correctness

Recursion: Introduction and Correctness Recursion: Introduction and Correctness CSE21 Winter 2017, Day 7 (B00), Day 4-5 (A00) January 25, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Today s Plan From last time: intersecting sorted lists and

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 20: Algorithm Design Techniques 12/2/2015 Daniel Bauer 1 Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways of

More information

Dynamic Programming. Weighted Interval Scheduling. Algorithmic Paradigms. Dynamic Programming

Dynamic Programming. Weighted Interval Scheduling. Algorithmic Paradigms. Dynamic Programming lgorithmic Paradigms Dynamic Programming reed Build up a solution incrementally, myopically optimizing some local criterion Divide-and-conquer Break up a problem into two sub-problems, solve each sub-problem

More information

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing

More information

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad DAA Unit- II Greedy and Dynamic Programming By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad 1 Greedy Method 2 Greedy Method Greedy Principal: are typically

More information

Math Circle: Recursion and Induction

Math Circle: Recursion and Induction Math Circle: Recursion and Induction Prof. Wickerhauser 1 Recursion What can we compute, using only simple formulas and rules that everyone can understand? 1. Let us use N to denote the set of counting

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lecture 6-8 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

Divide and Conquer. Andreas Klappenecker

Divide and Conquer. Andreas Klappenecker Divide and Conquer Andreas Klappenecker The Divide and Conquer Paradigm The divide and conquer paradigm is important general technique for designing algorithms. In general, it follows the steps: - divide

More information

Discrete Mathematics -- Chapter 10: Recurrence Relations

Discrete Mathematics -- Chapter 10: Recurrence Relations Discrete Mathematics -- Chapter 10: Recurrence Relations Hung-Yu Kao ( 高宏宇 ) Department of Computer Science and Information Engineering, National Cheng Kung University First glance at recurrence F n+2

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali March 17, 2014 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine solutions

More information

CHAPTER 8 Advanced Counting Techniques

CHAPTER 8 Advanced Counting Techniques 96 Chapter 8 Advanced Counting Techniques CHAPTER 8 Advanced Counting Techniques SECTION 8. Applications of Recurrence Relations 2. a) A permutation of a set with n elements consists of a choice of a first

More information

CS Lunch. Dynamic Programming Recipe. 2 Midterm 2! Slides17 - Segmented Least Squares.key - November 16, 2016

CS Lunch. Dynamic Programming Recipe. 2 Midterm 2! Slides17 - Segmented Least Squares.key - November 16, 2016 CS Lunch 1 Michelle Oraa Ali Tien Dao Vladislava Paskova Nan Zhuang Surabhi Sharma Wednesday, 12:15 PM Kendade 307 2 Midterm 2! Monday, November 21 In class Covers Greedy Algorithms Closed book Dynamic

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

CPS 616 DIVIDE-AND-CONQUER 6-1

CPS 616 DIVIDE-AND-CONQUER 6-1 CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

More information

12 Sequences and Recurrences

12 Sequences and Recurrences 12 Sequences and Recurrences A sequence is just what you think it is. It is often given by a formula known as a recurrence equation. 12.1 Arithmetic and Geometric Progressions An arithmetic progression

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and

More information

17 Advancement Operator Equations

17 Advancement Operator Equations November 14, 2017 17 Advancement Operator Equations William T. Trotter trotter@math.gatech.edu Review of Recurrence Equations (1) Problem Let r(n) denote the number of regions determined by n lines that

More information

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 Divide&Conquer: MergeSort Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 1 Divide-and-Conquer Algorithms Divide-and-conquer algorithms work according to the

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;

More information

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency Lecture 2 Fundamentals of the Analysis of Algorithm Efficiency 1 Lecture Contents 1. Analysis Framework 2. Asymptotic Notations and Basic Efficiency Classes 3. Mathematical Analysis of Nonrecursive Algorithms

More information

arxiv: v1 [math.co] 22 Jan 2013

arxiv: v1 [math.co] 22 Jan 2013 NESTED RECURSIONS, SIMULTANEOUS PARAMETERS AND TREE SUPERPOSITIONS ABRAHAM ISGUR, VITALY KUZNETSOV, MUSTAZEE RAHMAN, AND STEPHEN TANNY arxiv:1301.5055v1 [math.co] 22 Jan 2013 Abstract. We apply a tree-based

More information

CS Analysis of Recursive Algorithms and Brute Force

CS Analysis of Recursive Algorithms and Brute Force CS483-05 Analysis of Recursive Algorithms and Brute Force 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/

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

ICS141: Discrete Mathematics for Computer Science I

ICS141: Discrete Mathematics for Computer Science I ICS141: Discrete Mathematics for Computer Science I Dept. Information & Computer Sci., Jan Stelovsky based on slides by Dr. Baek and Dr. Still Originals by Dr. M. P. Frank and Dr. J.L. Gross Provided by

More information

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

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming Algorithms and Theory of Computation Lecture 9: Dynamic Programming Xiaohui Bei MAS 714 September 10, 2018 Nanyang Technological University MAS 714 September 10, 2018 1 / 21 Recursion in Algorithm Design

More information

ECOM Discrete Mathematics

ECOM Discrete Mathematics ECOM 2311- Discrete Mathematics Chapter # 3 : Algorithms Fall, 2013/2014 ECOM 2311- Discrete Mathematics - Ch.3 Dr. Musbah Shaat 1 / 41 Outline 1 Algorithms 2 The Growth of Functions 3 Complexity of Algorithms

More information

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction Math 4 Summer 01 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

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

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee Algorithm Analysis Recurrence Relation Chung-Ang University, Jaesung Lee Recursion 2 Recursion 3 Recursion in Real-world Fibonacci sequence = + Initial conditions: = 0 and = 1. = + = + = + 0, 1, 1, 2,

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

Appendix: Solving Recurrences

Appendix: Solving Recurrences ... O Zarathustra, who you are and must become behold you are the teacher of the eternal recurrence that is your destiny! That you as the first must teach this doctrine how could this great destiny not

More information

Applications. More Counting Problems. Complexity of Algorithms

Applications. More Counting Problems. Complexity of Algorithms Recurrences Applications More Counting Problems Complexity of Algorithms Part I Recurrences and Binomial Coefficients Paths in a Triangle P(0, 0) P(1, 0) P(1,1) P(2, 0) P(2,1) P(2, 2) P(3, 0) P(3,1) P(3,

More information

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers. MATH 4 Summer 011 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Lecture 4. Quicksort

Lecture 4. Quicksort Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking

More information

Sorting DS 2017/2018

Sorting DS 2017/2018 Sorting DS 2017/2018 Content Sorting based on comparisons Bubble sort Insertion sort Selection sort Merge sort Quick sort Counting sort Distribution sort FII, UAIC Lecture 8 DS 2017/2018 2 / 44 The sorting

More information

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

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 Aside: Golden Ratio Golden Ratio: A universal law. Golden ratio φ = lim n a n+b n a n = 1+ 5 2 a n+1 = a n + b n, b n = a n 1 Ruta (UIUC) CS473 1 Spring 2018 1 / 41 CS 473: Algorithms, Spring 2018 Dynamic

More information

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4 Do the following exercises from the text: Chapter (Section 3):, 1, 17(a)-(b), 3 Prove that 1 3 + 3 + + n 3 n (n + 1) for all n N Proof The proof is by induction on n For n N, let S(n) be the statement

More information

CSI2101-W08- Recurrence Relations

CSI2101-W08- Recurrence Relations Motivation CSI2101-W08- Recurrence Relations where do they come from modeling program analysis Solving Recurrence Relations by iteration arithmetic/geometric sequences linear homogenous recurrence relations

More information

Outline / Reading. Greedy Method as a fundamental algorithm design technique

Outline / Reading. Greedy Method as a fundamental algorithm design technique Greedy Method Outline / Reading Greedy Method as a fundamental algorithm design technique Application to problems of: Making change Fractional Knapsack Problem (Ch. 5.1.1) Task Scheduling (Ch. 5.1.2) Minimum

More information