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

Similar documents
MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Recurrence Relations

Notes for Recitation 14

CS483 Design and Analysis of Algorithms

Mergesort and Recurrences (CLRS 2.3, 4.4)

Divide and Conquer. Recurrence Relations

Algorithm Design and Analysis

Algorithms And Programming I. Lecture 5 Quicksort

CS483 Design and Analysis of Algorithms

data structures and algorithms lecture 2

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

CPS 616 DIVIDE-AND-CONQUER 6-1

Today s Outline. CS 362, Lecture 4. Annihilator Method. Lookup Table. Annihilators for recurrences with non-homogeneous terms Transformations

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

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

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Divide and Conquer Algorithms

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

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

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

Review Of Topics. Review: Induction

Advanced Counting Techniques. Chapter 8

Asymptotic Analysis and Recurrences

Introduction to Algorithms 6.046J/18.401J/SMA5503

Partition and Select

Introduction to Divide and Conquer

Analysis of Algorithms - Using Asymptotic Bounds -

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

Recurrences COMP 215

The Divide-and-Conquer Design Paradigm

CS173 Running Time and Big-O. Tandy Warnow

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

Divide and Conquer Algorithms

Week 5: Quicksort, Lower bound, Greedy

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

Section 5.3 Divide and Conquer Relations. 0,a m. - Division into thirds gives m = 3. Apply the telescoping technique described in Section 5.2.

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh

Inf 2B: Sorting, MergeSort and Divide-and-Conquer

Divide and Conquer. Andreas Klappenecker

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

COMP 382: Reasoning about algorithms

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

Algorithms Test 1. Question 1. (10 points) for (i = 1; i <= n; i++) { j = 1; while (j < n) {

Outline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference

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

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

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

Design and Analysis of Algorithms

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline

Fundamental Algorithms

Chapter 4 Divide-and-Conquer

Fundamental Algorithms

COMP 355 Advanced Algorithms

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Multidimensional Divide and Conquer 1 Skylines

Lecture 2: MergeSort. CS 341: Algorithms. Thu, Jan 10 th 2019

ITEC2620 Introduction to Data Structures

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background

Data Structures and Algorithms Chapter 3

CSE 613: Parallel Programming. Lecture 8 ( Analyzing Divide-and-Conquer Algorithms )

Methods for solving recurrences

A SUMMARY OF RECURSION SOLVING TECHNIQUES

CSC2100B Data Structures Analysis

1 Substitution method

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Outline. Part 5. Computa0onal Complexity (3) Compound Interest 2/15/12. Recurrence Rela0ons: An Overview. Recurrence Rela0ons: Formal Defini0on

Advanced Counting Techniques

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

Computational Complexity

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

COMP 9024, Class notes, 11s2, Class 1

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

COMP Analysis of Algorithms & Data Structures

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

Algorithm Analysis Divide and Conquer. Chung-Ang University, Jaesung Lee

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

COMP Analysis of Algorithms & Data Structures

Lecture 2: Divide and conquer and Dynamic programming

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

Algorithms. Quicksort. Slide credit: David Luebke (Virginia)

Divide-Conquer-Glue Algorithms

Topic 17. Analysis of Algorithms

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

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

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

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

CSI2101-W08- Recurrence Relations

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Chapter 5 Divide and Conquer

CS 2110: INDUCTION DISCUSSION TOPICS

Recurrence Relations

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort

Data Structures and Algorithms CSE 465

Omega notation. Transitivity etc.

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms )

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

Lecture 7: Dynamic Programming I: Optimal BSTs

Transcription:

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 characteristic equation has a multiple root then both a n n and a n n n are solutions. Today we will prove this directly. Consider the second order recurrence equation The characteristic equation has two identical roots a n a n a n 0 4, 4 if and only if. It follows. To prove that 4 a n n n is the solution we substitute this into the original recurrence Divide this by n n n n n n n n n n 0

V. Adamchi -7: Concepts of Mathematics and then collect terms with respect to n n 0 The first term is zero because is the roots of the characteristic equation. The second term is zero because and 4. Theorem. Let be a root of multiplicity p of the characteristic equation. Then are all solutions to the recurrence. Example. Find a general solution n, n n, n n,..., n p n a n 3 a n 3 a n a n3 The characteristic equation has a root of multiplicity 3. Therefore, is a solution of this recurrence equation. Exercise. Solve the recurrence Inhomogeneous Equations a n c c n c 3 n a n a n 7 a n 3 a n3 0 a 0, a, a 3 As an example of such recurrences we consider Fibonacci trees. This data structure is defined recursively as follows: the empty tree is a Fibonacci tree of order 0 a single node tree is a Fibonacci tree of order. a Fibonacci tree of order n has a left Fibonacci subtree of order n, and a right Fibonacci subtree of order n.

V. Adamchi 3 We want to count the number of nodes in a Fibonacci tree of order n. Let T n denote the number of nodes in a tree of order n. Then A recurrence of the form T n T n T n T 0 0, T a n a n... a n fn where all are constants and fn is a function other than the zero is called an inhomogeneous linear recurrence equation with constant coefficients. There is no a nown general method for solving such equations. We consider a one important particular case when the function fn is fn n pn wherepn is a polynomial and 0. The main idea is to transform a given inhomogeneous equation into a homogeneous one. Let us trace the idea on the Fibonacci tree recurrence. In order to cancel the right hand side, we consider the original equation along with the one obtained by replacing n n T n T n T n T n T n T n3 Next we subtract the second equation from the first T n T n T n3 0 T 0 0, T, T

V. Adamchi -7: Concepts of Mathematics This is the forth order homogeneous equation, which we can solve by the characteristic equation Solvex^3x^ 0, x x, x, x The general solution is given by The system for coefficients c has a solution After some algebra, we get which can be recognized as or n T n c c c n 3 T 0 c c c 3 0 T c c c 3 T c c c 3 c, c 3, c 3 3 0 0 T n n n n T n F n F n T n F n wherer F n is the Fibonacci number. You will see this sequence again in - when study AVL trees. n

V. Adamchi Divide-and-conquer Recurrences The divide-and-conquer algorithm consist of three steps: dividing a problem into smaller subproblems solving (recursively) each subproblem then combining solutions Suppose T n is the number of steps in the worst case needed to solve the problem of size n. Let us split a problem into a subproblems, each of which is of the input size n b where b. Observe, that the number of subproblems a is not necessarily equal to b. The total number of steps T n is obtained by all steps needed to solve smaller subproblems T nb plus the number needed to combine solutions into a final one. The following equation is called divide-and-conquer recurrence relation Here are some examples T n a T nb fn T n T n n T n 3 T n4 n T n T n3 n log n There are three main techniques to solve such recurrence equations: the iteration method the tree method the master-theorem method MergeSort Mergesort involves the following steps: Divide the array into two subarrays Sort each subarray Merge them into one (in a smart way!) Example.. divide it into two parts. sort each one 7 0 34 6 3 7 0 34 6 3

V. Adamchi -7: Concepts of Mathematics 0 7 6 3 34 3. merge into one (comparing, one by one, the paired elements from the two parts) (0 ) ( ) ( ) ( 6) ( 3) (3 7) (3 34) 0 6 7 3 34 Let T n denote the running time of the algorithm, i.e. the number of comparisons needed to sort n elements. We have the following recurrence equation for T n : T n T n n T 0 To get the feeling for the nature of the solution we consider a case when n is a power of, namely n. Then We divide both sides by and iterate it Using a bacward substitution, this leads to The finite sum is the geometric series Therefore, T T T T T T... steps... T T 0 T... T... x j x x j0

V. Adamchi 7 j j j j0 Thus or T T Since n, we finally obtain T n nlog n n