580
WS 2017/18 Efficient Algorithms and Data Structures Harald Räcke Fakultät für Informatik TU München http://www14.in.tum.de/lehre/2017WS/ea/ Winter Term 2017/18 Ernst Mayr, Harald Räcke 1/120

Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

WS 2017/18

Efficient Algorithmsand Data Structures

Harald Räcke

Fakultät für InformatikTU München

http://www14.in.tum.de/lehre/2017WS/ea/

Winter Term 2017/18

Ernst Mayr, Harald Räcke 1/120

Page 2: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

Ernst Mayr, Harald Räcke 2/120

Page 3: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 4: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 5: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 6: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 7: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 8: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 9: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 10: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 11: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 12: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 13: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4/120

Part I

Organizational Matters

ñ Modul: IN2003

ñ Name: “Efficient Algorithms and Data Structures”

“Effiziente Algorithmen und Datenstrukturen”

ñ ECTS: 8 Credit points

ñ Lectures:ñ 4 SWS

Mon 10:00–12:00 (Room Interim2)Fri 10:00–12:00 (Room Interim2)

ñ Webpage: http://www14.in.tum.de/lehre/2017WS/ea/

Page 14: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Lecturer

ñ Harald Räcke

ñ Email: [email protected]

ñ Room: 03.09.044

ñ Office hours: (by appointment)

Ernst Mayr, Harald Räcke 5/120

ñ Required knowledge:ñ IN0001, IN0003

“Introduction to Informatics 1/2”“Einführung in die Informatik 1/2”

ñ IN0007“Fundamentals of Algorithms and Data Structures”“Grundlagen: Algorithmen und Datenstrukturen” (GAD)

ñ IN0011“Basic Theoretic Informatics”“Einführung in die Theoretische Informatik” (THEO)

ñ IN0015“Discrete Structures”“Diskrete Strukturen” (DS)

ñ IN0018“Discrete Probability Theory”“Diskrete Wahrscheinlichkeitstheorie” (DWT)

Ernst Mayr, Harald Räcke 4

Page 15: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Tutorials

A01 Monday, 12:00–14:00, 00.08.038 (Stotz)

A02 Monday, 12:00–14:00, 00.09.038 (Kohler)

A03 Monday, 14:00–16:00, 03.10.011 (Sperr)

B04 Tuesday, 12:00–14:00, 03.11.018 (Kohler)

B05 Tuesday, 14:00–16:00, 00.08.038 (Matl)

B06 Tuesday, 16:00–18:00, 00.08.036 (Sperr)

C07 Wednesday, 10:00–12:00, 01.13.010 (Stotz)

D08 Thursday, 10:00–12:00, 00.08.038 (Kraft)

E09 Friday, 12:00–14:00, 00.13.009 (Kraft)

E10 Friday, 14:00–16:00, 00.08.036 (Matl)

Ernst Mayr, Harald Räcke 6/120

The Lecturer

ñ Harald Räcke

ñ Email: [email protected]

ñ Room: 03.09.044

ñ Office hours: (by appointment)

Ernst Mayr, Harald Räcke 5

Page 16: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7/120

Tutorials

A01 Monday, 12:00–14:00, 00.08.038 (Stotz)

A02 Monday, 12:00–14:00, 00.09.038 (Kohler)

A03 Monday, 14:00–16:00, 03.10.011 (Sperr)

B04 Tuesday, 12:00–14:00, 03.11.018 (Kohler)

B05 Tuesday, 14:00–16:00, 00.08.038 (Matl)

B06 Tuesday, 16:00–18:00, 00.08.036 (Sperr)

C07 Wednesday, 10:00–12:00, 01.13.010 (Stotz)

D08 Thursday, 10:00–12:00, 00.08.038 (Kraft)

E09 Friday, 12:00–14:00, 00.13.009 (Kraft)

E10 Friday, 14:00–16:00, 00.08.036 (Matl)

Ernst Mayr, Harald Räcke 6

Page 17: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 18: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 19: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 20: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 21: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 22: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8/120

Assignment sheets

In order to pass the module you need to pass an exam.

Ernst Mayr, Harald Räcke 7

Page 23: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9/120

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8

Page 24: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9/120

Assessment

Assignment Sheets:

ñ An assignment sheet is usually made available on Monday

on the module webpage.

ñ Solutions have to be handed in in the following week before

the lecture on Monday.

ñ You can hand in your solutions by putting them in the

mailbox "Efficient Algorithms" on the basement floor in the

MI-building.

ñ Solutions have to be given in English.

ñ Solutions will be discussed in the tutorial of the week when

the sheet has been handed in, i.e, sheet may not be

corrected by this time.

ñ You can submit solutions in groups of up to 2 people.

Ernst Mayr, Harald Räcke 8

Page 25: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 26: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 27: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 28: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 29: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 30: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 31: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 32: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10/120

Assessment

Assignment Sheets:

ñ Submissions must be handwritten by a member of the

group. Please indicate who wrote the submission.

ñ Don’t forget name and student id number for each group

member.

Ernst Mayr, Harald Räcke 9

Page 33: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Assessment

Requirements for Bonus

ñ 50% of the points are achieved on submissions 1–7,

ñ 50% of the points are achieved on submissions 8–13,

ñ each group member has written at least 4 solutions.

Ernst Mayr, Harald Räcke 11/120

Assessment

Assignment can be used to improve you grade

ñ If you obtain a bonus your grade will improve according to

the following function

f(x) = 1

10round(10(

round(3x)−13

))1 < x ≤ 4

x otw.

ñ It will improve by 0.3 or 0.4, respectively.Examples:

ñ 3.3→ 3.0ñ 2.0→ 1.7ñ 3.7→ 3.3ñ 1.0→ 1.0ñ > 4.0 no improvement

Ernst Mayr, Harald Räcke 10

Page 34: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

1 Contents

ñ Foundationsñ Machine modelsñ Efficiency measuresñ Asymptotic notationñ Recursion

ñ Higher Data Structuresñ Search treesñ Hashingñ Priority queuesñ Union/Find data structures

ñ Cuts/Flows

ñ Matchings

1 Contents

Ernst Mayr, Harald Räcke 12/120

Page 35: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

1 Contents

ñ Foundationsñ Machine modelsñ Efficiency measuresñ Asymptotic notationñ Recursion

ñ Higher Data Structuresñ Search treesñ Hashingñ Priority queuesñ Union/Find data structures

ñ Cuts/Flows

ñ Matchings

1 Contents

Ernst Mayr, Harald Räcke 12/120

Page 36: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

1 Contents

ñ Foundationsñ Machine modelsñ Efficiency measuresñ Asymptotic notationñ Recursion

ñ Higher Data Structuresñ Search treesñ Hashingñ Priority queuesñ Union/Find data structures

ñ Cuts/Flows

ñ Matchings

1 Contents

Ernst Mayr, Harald Räcke 12/120

Page 37: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

1 Contents

ñ Foundationsñ Machine modelsñ Efficiency measuresñ Asymptotic notationñ Recursion

ñ Higher Data Structuresñ Search treesñ Hashingñ Priority queuesñ Union/Find data structures

ñ Cuts/Flows

ñ Matchings

1 Contents

Ernst Mayr, Harald Räcke 12/120

Page 38: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

2 Literatur

Alfred V. Aho, John E. Hopcroft, Jeffrey D. Ullman:

The design and analysis of computer algorithms,

Addison-Wesley Publishing Company: Reading (MA), 1974

Thomas H. Cormen, Charles E. Leiserson, Ron L. Rivest,

Clifford Stein:

Introduction to algorithms,

McGraw-Hill, 1990

Michael T. Goodrich, Roberto Tamassia:

Algorithm design: Foundations, analysis, and internet

examples,

John Wiley & Sons, 2002

2 Literatur

Ernst Mayr, Harald Räcke 13/120

Page 39: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

2 Literatur

Volker Heun:

Grundlegende Algorithmen: Einführung in den Entwurf und

die Analyse effizienter Algorithmen,

2. Auflage, Vieweg, 2003

Jon Kleinberg, Eva Tardos:

Algorithm Design,

Addison-Wesley, 2005

Donald E. Knuth:

The art of computer programming. Vol. 1: Fundamental

Algorithms,

3. Auflage, Addison-Wesley Publishing Company: Reading

(MA), 1997

2 Literatur

Ernst Mayr, Harald Räcke 14/120

2 Literatur

Alfred V. Aho, John E. Hopcroft, Jeffrey D. Ullman:

The design and analysis of computer algorithms,

Addison-Wesley Publishing Company: Reading (MA), 1974

Thomas H. Cormen, Charles E. Leiserson, Ron L. Rivest,

Clifford Stein:

Introduction to algorithms,

McGraw-Hill, 1990

Michael T. Goodrich, Roberto Tamassia:

Algorithm design: Foundations, analysis, and internet

examples,

John Wiley & Sons, 2002

2 Literatur

Ernst Mayr, Harald Räcke 13

Page 40: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

2 Literatur

Donald E. Knuth:

The art of computer programming. Vol. 3: Sorting and

Searching,

3. Auflage, Addison-Wesley Publishing Company: Reading

(MA), 1997

Christos H. Papadimitriou, Kenneth Steiglitz:

Combinatorial Optimization: Algorithms and Complexity,

Prentice Hall, 1982

Uwe Schöning:

Algorithmik,

Spektrum Akademischer Verlag, 2001

Steven S. Skiena:

The Algorithm Design Manual,

Springer, 1998

2 Literatur

Ernst Mayr, Harald Räcke 15/120

2 Literatur

Volker Heun:

Grundlegende Algorithmen: Einführung in den Entwurf und

die Analyse effizienter Algorithmen,

2. Auflage, Vieweg, 2003

Jon Kleinberg, Eva Tardos:

Algorithm Design,

Addison-Wesley, 2005

Donald E. Knuth:

The art of computer programming. Vol. 1: Fundamental

Algorithms,

3. Auflage, Addison-Wesley Publishing Company: Reading

(MA), 1997

2 Literatur

Ernst Mayr, Harald Räcke 14

Page 41: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Part II

Foundations

Ernst Mayr, Harald Räcke 16/120

Page 42: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17/120

Page 43: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17/120

Page 44: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17/120

Page 45: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

n! “n factorial”(nk

)“n choose k”

xi “x subscript i”“x sub i”“x i”

logb a “log to the base b of a”

“log a to the base b”

f : X → Y ,x , x2

f is a function that maps from domain (Definitionsbereich) X to

codomain (Zielmenge) Y . The set y ∈ Y | ∃x ∈ X : f(x) = yis the image or the range of the function

(Bildbereich/Wertebereich).

Ernst Mayr, Harald Räcke 18/120

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17

Page 46: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

n! “n factorial”(nk

)“n choose k”

xi “x subscript i”“x sub i”“x i”

logb a “log to the base b of a”

“log a to the base b”

f : X → Y ,x , x2

f is a function that maps from domain (Definitionsbereich) X to

codomain (Zielmenge) Y . The set y ∈ Y | ∃x ∈ X : f(x) = yis the image or the range of the function

(Bildbereich/Wertebereich).

Ernst Mayr, Harald Räcke 18/120

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17

Page 47: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

n! “n factorial”(nk

)“n choose k”

xi “x subscript i”“x sub i”“x i”

logb a “log to the base b of a”

“log a to the base b”

f : X → Y ,x , x2

f is a function that maps from domain (Definitionsbereich) X to

codomain (Zielmenge) Y . The set y ∈ Y | ∃x ∈ X : f(x) = yis the image or the range of the function

(Bildbereich/Wertebereich).

Ernst Mayr, Harald Räcke 18/120

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17

Page 48: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

n! “n factorial”(nk

)“n choose k”

xi “x subscript i”“x sub i”“x i”

logb a “log to the base b of a”

“log a to the base b”

f : X → Y ,x , x2

f is a function that maps from domain (Definitionsbereich) X to

codomain (Zielmenge) Y . The set y ∈ Y | ∃x ∈ X : f(x) = yis the image or the range of the function

(Bildbereich/Wertebereich).

Ernst Mayr, Harald Räcke 18/120

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17

Page 49: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Vocabularies

n! “n factorial”(nk

)“n choose k”

xi “x subscript i”“x sub i”“x i”

logb a “log to the base b of a”

“log a to the base b”

f : X → Y ,x , x2

f is a function that maps from domain (Definitionsbereich) X to

codomain (Zielmenge) Y . The set y ∈ Y | ∃x ∈ X : f(x) = yis the image or the range of the function

(Bildbereich/Wertebereich).

Ernst Mayr, Harald Räcke 18/120

Vocabularies

a · b “a times b”

“a multiplied by b”

“a into b”ab “a divided by b”

“a by b”

“a over b”

(a: numerator (Zähler), b: denominator (Nenner))

ab “a raised to the b-th power”

“a to the b-th”

“a raised to the power of b”

“a to the power of b”

“a raised to b”

“a to the b”

“a raised by the exponent of b”

Ernst Mayr, Harald Räcke 17

Page 50: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

3 Goals

ñ Gain knowledge about efficient algorithms for important

problems, i.e., learn how to solve certain types of problems

efficiently.

ñ Learn how to analyze and judge the efficiency of algorithms.

ñ Learn how to design efficient algorithms.

3 Goals

Ernst Mayr, Harald Räcke 19/120

Page 51: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

3 Goals

ñ Gain knowledge about efficient algorithms for important

problems, i.e., learn how to solve certain types of problems

efficiently.

ñ Learn how to analyze and judge the efficiency of algorithms.

ñ Learn how to design efficient algorithms.

3 Goals

Ernst Mayr, Harald Räcke 19/120

Page 52: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

3 Goals

ñ Gain knowledge about efficient algorithms for important

problems, i.e., learn how to solve certain types of problems

efficiently.

ñ Learn how to analyze and judge the efficiency of algorithms.

ñ Learn how to design efficient algorithms.

3 Goals

Ernst Mayr, Harald Räcke 19/120

Page 53: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 54: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 55: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 56: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 57: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 58: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 59: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 60: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20/120

Page 61: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 62: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 63: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 64: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 65: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 66: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 67: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 68: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 69: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21/120

4 Modelling Issues

What do you measure?

ñ Memory requirement

ñ Running time

ñ Number of comparisons

ñ Number of multiplications

ñ Number of hard-disc accesses

ñ Program size

ñ Power consumption

ñ . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 20

Page 70: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22/120

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21

Page 71: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22/120

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21

Page 72: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22/120

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21

Page 73: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22/120

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21

Page 74: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22/120

4 Modelling Issues

How do you measure?

ñ Implementing and testing on representative inputsñ How do you choose your inputs?ñ May be very time-consuming.ñ Very reliable results if done correctly.ñ Results only hold for a specific machine and for a specific

set of inputs.

ñ Theoretical analysis in a specific model of computation.ñ Gives asymptotic bounds like “this algorithm always runs in

time O(n2)”.ñ Typically focuses on the worst case.ñ Can give lower bounds like “any comparison-based sorting

algorithm needs at least Ω(n logn) comparisons in theworst case”.

4 Modelling Issues

Ernst Mayr, Harald Räcke 21

Page 75: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23/120

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22

Page 76: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23/120

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22

Page 77: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23/120

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22

Page 78: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23/120

4 Modelling Issues

Input length

The theoretical bounds are usually given by a function f : N→ Nthat maps the input length to the running time (or storage

space, comparisons, multiplications, program size etc.).

The input length may e.g. be

ñ the size of the input (number of bits)

ñ the number of arguments

Example 1

Suppose n numbers from the interval 1, . . . ,N have to be

sorted. In this case we usually say that the input length is ninstead of e.g. n logN, which would be the number of bits

required to encode the input.

4 Modelling Issues

Ernst Mayr, Harald Räcke 22

Page 79: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24/120

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23

Page 80: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24/120

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23

Page 81: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24/120

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23

Page 82: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24/120

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23

Page 83: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24/120

Model of Computation

How to measure performance

1. Calculate running time and storage space etc. on a

simplified, idealized model of computation, e.g. Random

Access Machine (RAM), Turing Machine (TM), . . .

2. Calculate number of certain basic operations: comparisons,

multiplications, harddisc accesses, . . .

Version 2. is often easier, but focusing on one type of operation

makes it more difficult to obtain meaningful results.

4 Modelling Issues

Ernst Mayr, Harald Räcke 23

Page 84: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25/120

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24

Page 85: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25/120

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24

Page 86: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25/120

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24

Page 87: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25/120

Turing Machine

ñ Very simple model of computation.

ñ Only the “current” memory location can be altered.

ñ Very good model for discussing computabiliy, or polynomial

vs. exponential time.

ñ Some simple problems like recognizing whether input is of

the form xx, where x is a string, have quadratic lower

bound.

=⇒ Not a good model for developing efficient algorithms.

0 11 0 0 1 0 0 1 0 0 1 0 0 1 1 0

controlunit

statestate holds program and canact as constant size memory

. . . . . .

4 Modelling Issues

Ernst Mayr, Harald Räcke 24

Page 88: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 89: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 90: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 91: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 92: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 93: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 94: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 95: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 96: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 97: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26/120

Random Access Machine (RAM)

ñ Input tape and output tape (sequences of zeros and ones;

unbounded length).

ñ Memory unit: infinite but countable number of registers

R[0], R[1], R[2], . . . .ñ Registers hold integers.

ñ Indirect addressing.

Note that in the picture on the rightthe tapes are one-directional, and thata READ- or WRITE-operation always ad-vances its tape.

0 11 0 0 1 0 0 1

0 0 1 1

R[0]

R[1]

R[2]

R[3]

R[4]

R[5]

input tape

output tape

memory

controlunit

. . . . . .

. . . . . ....

4 Modelling Issues

Ernst Mayr, Harald Räcke 25

Page 98: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 99: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 100: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 101: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 102: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 103: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27/120

Random Access Machine (RAM)

Operations

ñ input operations (input tape → R[i])ñ READ i

ñ output operations (R[i]→ output tape)ñ WRITE i

ñ register-register transfersñ R[j] := R[i]ñ R[j] := 4

ñ indirect addressingñ R[j] := R[R[i]]

loads the content of the R[i]-th register into the j-thregister

ñ R[R[i]] := R[j]loads the content of the j-th into the R[i]-th register

4 Modelling Issues

Ernst Mayr, Harald Räcke 26

Page 104: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28/120

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27

Page 105: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28/120

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27

Page 106: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28/120

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27

Page 107: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28/120

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27

Page 108: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28/120

Random Access Machine (RAM)

Operations

ñ branching (including loops) based on comparisonsñ jump x

jumps to position x in the program;sets instruction counter to x;reads the next operation to perform from register R[x]

ñ jumpz x R[i]jump to x if R[i] = 0if not the instruction counter is increased by 1;

ñ jumpi ijump to R[i] (indirect jump);

ñ arithmetic instructions: +, −, ×, /ñ R[i] := R[j] + R[k];R[i] := -R[k]; The jump-directives are very close to the

jump-instructions contained in the as-sembler language of real machines.

4 Modelling Issues

Ernst Mayr, Harald Räcke 27

Page 109: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 110: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 111: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 112: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 113: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 114: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 115: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29/120

Model of Computation

ñ uniform cost model

Every operation takes time 1.

ñ logarithmic cost modelThe cost depends on the content of memory cells:

ñ The time for a step is equal to the largest operand involved;ñ The storage space of a register is equal to the length (in

bits) of the largest value ever stored in it.

Bounded word RAM model: cost is uniform but the largest

value stored in a register may not exceed 2w , where usually

w = log2n.The latter model is quite realistic as the word-size ofa standard computer that handles a problem of size nmust be at least log2 n as otherwise the computer couldeither not store the problem instance or not address allits memory.

4 Modelling Issues

Ernst Mayr, Harald Räcke 28

Page 116: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ best-case complexity:

Cbc(n) :=minC(x) | |x| = nUsually easy to analyze, but not very meaningful.

ñ worst-case complexity:

Cwc(n) :=maxC(x) | |x| = nUsually moderately easy to analyze; sometimes too

pessimistic.ñ average case complexity:

Cavg(n) := 1|In|

∑|x|=n

C(x)

more general: probability measure µ

Cavg(n) :=∑x∈In

µ(x) · C(x)

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 117: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ best-case complexity:

Cbc(n) :=minC(x) | |x| = nUsually easy to analyze, but not very meaningful.

ñ worst-case complexity:

Cwc(n) :=maxC(x) | |x| = nUsually moderately easy to analyze; sometimes too

pessimistic.ñ average case complexity:

Cavg(n) := 1|In|

∑|x|=n

C(x)

more general: probability measure µ

Cavg(n) :=∑x∈In

µ(x) · C(x)

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 118: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ best-case complexity:

Cbc(n) :=minC(x) | |x| = nUsually easy to analyze, but not very meaningful.

ñ worst-case complexity:

Cwc(n) :=maxC(x) | |x| = nUsually moderately easy to analyze; sometimes too

pessimistic.ñ average case complexity:

Cavg(n) := 1|In|

∑|x|=n

C(x)

more general: probability measure µ

Cavg(n) :=∑x∈In

µ(x) · C(x)

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 119: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ best-case complexity:

Cbc(n) :=minC(x) | |x| = nUsually easy to analyze, but not very meaningful.

ñ worst-case complexity:

Cwc(n) :=maxC(x) | |x| = nUsually moderately easy to analyze; sometimes too

pessimistic.ñ average case complexity:

Cavg(n) := 1|In|

∑|x|=n

C(x)

more general: probability measure µ

Cavg(n) :=∑x∈In

µ(x) · C(x)

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 120: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ amortized complexity:

The average cost of data structure operations over a worst

case sequence of operations.

ñ randomized complexity:

The algorithm may use random bits. Expected running time

(over all possible choices of random bits) for a fixed input

x. Then take the worst-case over all x with |x| = n.

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 121: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

C(x)cost of instancex

|x| input length ofinstance x

Inset of instancesof length n

There are different types of complexity bounds:

ñ amortized complexity:

The average cost of data structure operations over a worst

case sequence of operations.

ñ randomized complexity:

The algorithm may use random bits. Expected running time

(over all possible choices of random bits) for a fixed input

x. Then take the worst-case over all x with |x| = n.

4 Modelling Issues

Ernst Mayr, Harald Räcke 30/120

4 Modelling Issues

Example 2

Algorithm 1 RepeatedSquaring(n)1: r ← 2;

2: for i = 1→ n do

3: r ← r2

4: return r

ñ running time:ñ uniform model: n stepsñ logarithmic model: 1+ 2+ 4+ · · · + 2n = 2n+1 − 1 = Θ(2n)

ñ space requirement:ñ uniform model: O(1)ñ logarithmic model: O(2n)

4 Modelling Issues

Ernst Mayr, Harald Räcke 29

Page 122: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31/120

Page 123: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31/120

Page 124: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31/120

Page 125: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31/120

Page 126: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31/120

Page 127: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32/120

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31

Page 128: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32/120

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31

Page 129: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32/120

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31

Page 130: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32/120

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31

Page 131: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32/120

5 Asymptotic Notation

We are usually not interested in exact running times, but only in

an asymptotic classification of the running time, that ignores

constant factors and constant additive offsets.

ñ We are usually interested in the running times for large

values of n. Then constant additive terms do not play an

important role.

ñ An exact analysis (e.g. exactly counting the number of

operations in a RAM) may be hard, but wouldn’t lead to

more precise results as the computational model is already

quite a distance from reality.

ñ A linear speed-up (i.e., by a constant factor) is always

possible by e.g. implementing the algorithm on a faster

machine.

ñ Running time should be expressed by simple functions.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 31

Page 132: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33/120

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32

Page 133: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33/120

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32

Page 134: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33/120

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32

Page 135: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33/120

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32

Page 136: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33/120

Asymptotic Notation

Formal Definition

Let f denote functions from N to R+.

ñ O(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow not faster than f )

ñ Ω(f ) = g | ∃c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow not slower than f )

ñ Θ(f ) = Ω(f )∩O(f )(functions that asymptotically have the same growth as f )

ñ o(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≤ c · f(n)](set of functions that asymptotically grow slower than f )

ñ ω(f) = g | ∀c > 0 ∃n0 ∈ N0 ∀n ≥ n0 : [g(n) ≥ c · f(n)](set of functions that asymptotically grow faster than f )

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 32

Page 137: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34/120

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33

Page 138: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34/120

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33

Page 139: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34/120

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33

Page 140: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34/120

Asymptotic Notation

There is an equivalent definition using limes notation (assuming

that the respective limes exists). f and g are functions from N0

to R+0 .

ñ g ∈ O(f ): 0 ≤ limn→∞

g(n)f(n)

<∞

ñ g ∈ Ω(f ): 0 < limn→∞

g(n)f(n)

≤ ∞

ñ g ∈ Θ(f ): 0 < limn→∞

g(n)f(n)

<∞

ñ g ∈ o(f): limn→∞

g(n)f(n)

= 0

ñ g ∈ω(f): limn→∞

g(n)f(n)

= ∞

• Note that for the version of the Lan-dau notation defined here, we as-sume that f and g are positive func-tions.

• There also exist versions for arbitraryfunctions, and for the case that thelimes is not infinity.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 33

Page 141: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 + 3n+ 1 = 2n2 +Θ(n)

Here, Θ(n) stands for an anonymous function in the set Θ(n)that makes the expression true.

Note that Θ(n) is on the right hand side, otw. this interpretation

is wrong.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 35/120

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34

Page 142: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 + 3n+ 1 = 2n2 +Θ(n)

Here, Θ(n) stands for an anonymous function in the set Θ(n)that makes the expression true.

Note that Θ(n) is on the right hand side, otw. this interpretation

is wrong.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 35/120

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34

Page 143: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 + 3n+ 1 = 2n2 +Θ(n)

Here, Θ(n) stands for an anonymous function in the set Θ(n)that makes the expression true.

Note that Θ(n) is on the right hand side, otw. this interpretation

is wrong.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 35/120

Asymptotic Notation

Abuse of notation

1. People write f = O(g), when they mean f ∈ O(g). This is

not an equality (how could a function be equal to a set of

functions).

2. People write f(n) = O(g(n)), when they mean f ∈ O(g),with f : N→ R+, n, f(n), and g : N→ R+, n, g(n).

3. People write e.g. h(n) = f(n)+ o(g(n)) when they mean

that there exists a function z : N→ R+, n, z(n), z ∈ o(g)such that h(n) = f(n)+ z(n).

4. People write O(f (n)) = O(g(n)), when they mean

O(f (n)) ⊆ O(g(n)). Again this is not an equality.3. This is particularly useful if you do notwant to ignore constant factors. For ex-ample the median of n elements canbe determined using 3

2n+o(n) compar-isons.

2. In this context f(n) does not mean thefunction f evaluated at n, but insteadit is a shorthand for the function itself(leaving out domain and codomain andonly giving the rule of correspondenceof the function).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 34

Page 144: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 +O(n) = Θ(n2)

Regardless of how we choose the anonymous function

f(n) ∈ O(n) there is an anonymous function g(n) ∈ Θ(n2)that makes the expression true.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 36/120

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 + 3n+ 1 = 2n2 +Θ(n)

Here, Θ(n) stands for an anonymous function in the set Θ(n)that makes the expression true.

Note that Θ(n) is on the right hand side, otw. this interpretation

is wrong.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 35

Page 145: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 +O(n) = Θ(n2)

Regardless of how we choose the anonymous function

f(n) ∈ O(n) there is an anonymous function g(n) ∈ Θ(n2)that makes the expression true.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 36/120

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 + 3n+ 1 = 2n2 +Θ(n)

Here, Θ(n) stands for an anonymous function in the set Θ(n)that makes the expression true.

Note that Θ(n) is on the right hand side, otw. this interpretation

is wrong.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 35

Page 146: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

n∑i=1

Θ(i) = Θ(n2)

Careful!

“It is understood” that every occurence of an O-symbol (or

Θ,Ω, o,ω) on the left represents one anonymous function.

Hence, the left side is not equal to

Θ(1)+Θ(2)+ · · · +Θ(n− 1)+Θ(n)

The Θ(i)-symbol on the left rep-resents one anonymous functionf : N → R+, and then

∑i f(i) is

computed.

Θ(1)+Θ(2)+· · ·+Θ(n−1)+Θ(n) doesnot really have a reasonable interpreta-tion.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 37/120

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 +O(n) = Θ(n2)

Regardless of how we choose the anonymous function

f(n) ∈ O(n) there is an anonymous function g(n) ∈ Θ(n2)that makes the expression true.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 36

Page 147: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

n∑i=1

Θ(i) = Θ(n2)

Careful!

“It is understood” that every occurence of an O-symbol (or

Θ,Ω, o,ω) on the left represents one anonymous function.

Hence, the left side is not equal to

Θ(1)+Θ(2)+ · · · +Θ(n− 1)+Θ(n)

The Θ(i)-symbol on the left rep-resents one anonymous functionf : N → R+, and then

∑i f(i) is

computed.

Θ(1)+Θ(2)+· · ·+Θ(n−1)+Θ(n) doesnot really have a reasonable interpreta-tion.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 37/120

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 +O(n) = Θ(n2)

Regardless of how we choose the anonymous function

f(n) ∈ O(n) there is an anonymous function g(n) ∈ Θ(n2)that makes the expression true.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 36

Page 148: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

How do we interpret an expression like:

n∑i=1

Θ(i) = Θ(n2)

Careful!

“It is understood” that every occurence of an O-symbol (or

Θ,Ω, o,ω) on the left represents one anonymous function.

Hence, the left side is not equal to

Θ(1)+Θ(2)+ · · · +Θ(n− 1)+Θ(n)

The Θ(i)-symbol on the left rep-resents one anonymous functionf : N → R+, and then

∑i f(i) is

computed.

Θ(1)+Θ(2)+· · ·+Θ(n−1)+Θ(n) doesnot really have a reasonable interpreta-tion.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 37/120

Asymptotic Notation in Equations

How do we interpret an expression like:

2n2 +O(n) = Θ(n2)

Regardless of how we choose the anonymous function

f(n) ∈ O(n) there is an anonymous function g(n) ∈ Θ(n2)that makes the expression true.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 36

Page 149: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

We can view an expression containing asymptotic notation as

generating a set:

n2 · O(n)+O(logn)

represents

f : N→ R+ | f(n) = n2 · g(n)+ h(n)

with g(n) ∈ O(n) and h(n) ∈ O(logn)

Recall that according to the previousslide e.g. the expressions

∑ni=1O(i) and∑n/2

i=1 O(i)+∑ni=n/2+1O(i) generate dif-

ferent sets.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 38/120

Asymptotic Notation in Equations

How do we interpret an expression like:

n∑i=1

Θ(i) = Θ(n2)

Careful!

“It is understood” that every occurence of an O-symbol (or

Θ,Ω, o,ω) on the left represents one anonymous function.

Hence, the left side is not equal to

Θ(1)+Θ(2)+ · · · +Θ(n− 1)+Θ(n)

The Θ(i)-symbol on the left rep-resents one anonymous functionf : N → R+, and then

∑i f(i) is

computed.

Θ(1)+Θ(2)+· · ·+Θ(n−1)+Θ(n) doesnot really have a reasonable interpreta-tion.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 37

Page 150: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39/120

Asymptotic Notation in Equations

We can view an expression containing asymptotic notation as

generating a set:

n2 · O(n)+O(logn)

represents

f : N→ R+ | f(n) = n2 · g(n)+ h(n)

with g(n) ∈ O(n) and h(n) ∈ O(logn)

Recall that according to the previousslide e.g. the expressions

∑ni=1O(i) and∑n/2

i=1 O(i)+∑ni=n/2+1O(i) generate dif-

ferent sets.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 38

Page 151: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40/120

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39

Page 152: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40/120

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39

Page 153: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40/120

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39

Page 154: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40/120

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39

Page 155: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40/120

Asymptotic Notation in Equations

Then an asymptotic equation can be interpreted as

containement btw. two sets:

n2 · O(n)+O(logn) = Θ(n2)

represents

n2 · O(n)+O(logn) ⊆ Θ(n2)

Note that the equation does not hold.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 39

Page 156: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41/120

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40

Page 157: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41/120

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40

Page 158: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41/120

Asymptotic Notation

Lemma 3

Let f , g be functions with the property

∃n0 > 0∀n ≥ n0 : f(n) > 0 (the same for g). Then

ñ c · f(n) ∈ Θ(f (n)) for any constant cñ O(f (n))+O(g(n)) = O(f (n)+ g(n))ñ O(f (n)) · O(g(n)) = O(f (n) · g(n))ñ O(f (n))+O(g(n)) = O(maxf(n), g(n))

The expressions also hold for Ω. Note that this means that

f(n)+ g(n) ∈ Θ(maxf(n), g(n)).

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 40

Page 159: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

In general asymptotic classification of running times is a good

measure for comparing algorithms:

ñ If the running time analysis is tight and actually occurs in

practise (i.e., the asymptotic bound is not a purely

theoretical worst-case bound), then the algorithm that has

better asymptotic running time will always outperform a

weaker algorithm for large enough values of n.

ñ However, suppose that I have two algorithms:ñ Algorithm A. Running time f(n) = 1000 logn = O(logn).ñ Algorithm B. Running time g(n) = log2n.

Clearly f = o(g). However, as long as logn ≤ 1000

Algorithm B will be more efficient.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 42/120

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41

Page 160: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

In general asymptotic classification of running times is a good

measure for comparing algorithms:

ñ If the running time analysis is tight and actually occurs in

practise (i.e., the asymptotic bound is not a purely

theoretical worst-case bound), then the algorithm that has

better asymptotic running time will always outperform a

weaker algorithm for large enough values of n.

ñ However, suppose that I have two algorithms:ñ Algorithm A. Running time f(n) = 1000 logn = O(logn).ñ Algorithm B. Running time g(n) = log2n.

Clearly f = o(g). However, as long as logn ≤ 1000

Algorithm B will be more efficient.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 42/120

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41

Page 161: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

In general asymptotic classification of running times is a good

measure for comparing algorithms:

ñ If the running time analysis is tight and actually occurs in

practise (i.e., the asymptotic bound is not a purely

theoretical worst-case bound), then the algorithm that has

better asymptotic running time will always outperform a

weaker algorithm for large enough values of n.

ñ However, suppose that I have two algorithms:ñ Algorithm A. Running time f(n) = 1000 logn = O(logn).ñ Algorithm B. Running time g(n) = log2n.

Clearly f = o(g). However, as long as logn ≤ 1000

Algorithm B will be more efficient.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 42/120

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41

Page 162: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

In general asymptotic classification of running times is a good

measure for comparing algorithms:

ñ If the running time analysis is tight and actually occurs in

practise (i.e., the asymptotic bound is not a purely

theoretical worst-case bound), then the algorithm that has

better asymptotic running time will always outperform a

weaker algorithm for large enough values of n.

ñ However, suppose that I have two algorithms:ñ Algorithm A. Running time f(n) = 1000 logn = O(logn).ñ Algorithm B. Running time g(n) = log2n.

Clearly f = o(g). However, as long as logn ≤ 1000

Algorithm B will be more efficient.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 42/120

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41

Page 163: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Asymptotic Notation

In general asymptotic classification of running times is a good

measure for comparing algorithms:

ñ If the running time analysis is tight and actually occurs in

practise (i.e., the asymptotic bound is not a purely

theoretical worst-case bound), then the algorithm that has

better asymptotic running time will always outperform a

weaker algorithm for large enough values of n.

ñ However, suppose that I have two algorithms:ñ Algorithm A. Running time f(n) = 1000 logn = O(logn).ñ Algorithm B. Running time g(n) = log2n.

Clearly f = o(g). However, as long as logn ≤ 1000

Algorithm B will be more efficient.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 42/120

Asymptotic Notation

Comments

ñ Do not use asymptotic notation within induction proofs.

ñ For any constants a,b we have logan = Θ(logb n).Therefore, we will usually ignore the base of a logarithm

within asymptotic notation.

ñ In general logn = log2n, i.e., we use 2 as the default base

for the logarithm.

5 Asymptotic Notation

Ernst Mayr, Harald Räcke 41

Page 164: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Algorithm 2 mergesort(listL)1: n← size(L)2: if n ≤ 1 return L3: L1 ← L[1 · · · bn

2c]

4: L2 ← L[bn2c + 1 · · ·n]

5: mergesort(L1)6: mergesort(L2)7: L←merge(L1, L2)8: return L

This algorithm requires

T(n) = T(⌈n

2

⌉)+ T

(⌊n2

⌋)+O(n) ≤ 2T

(⌈n2

⌉)+O(n)

comparisons when n > 1 and 0 comparisons when n ≤ 1.

6 Recurrences

Ernst Mayr, Harald Räcke 43/120

Page 165: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Algorithm 2 mergesort(listL)1: n← size(L)2: if n ≤ 1 return L3: L1 ← L[1 · · · bn

2c]

4: L2 ← L[bn2c + 1 · · ·n]

5: mergesort(L1)6: mergesort(L2)7: L←merge(L1, L2)8: return L

This algorithm requires

T(n) = T(⌈n

2

⌉)+ T

(⌊n2

⌋)+O(n) ≤ 2T

(⌈n2

⌉)+O(n)

comparisons when n > 1 and 0 comparisons when n ≤ 1.

6 Recurrences

Ernst Mayr, Harald Räcke 43/120

Page 166: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Recurrences

How do we bring the expression for the number of comparisons

(≈ running time) into a closed form?

For this we need to solve the recurrence.

6 Recurrences

Ernst Mayr, Harald Räcke 44/120

6 Recurrences

Algorithm 2 mergesort(listL)1: n← size(L)2: if n ≤ 1 return L3: L1 ← L[1 · · · bn

2c]

4: L2 ← L[bn2c + 1 · · ·n]

5: mergesort(L1)6: mergesort(L2)7: L←merge(L1, L2)8: return L

This algorithm requires

T(n) = T(⌈n

2

⌉)+ T

(⌊n2

⌋)+O(n) ≤ 2T

(⌈n2

⌉)+O(n)

comparisons when n > 1 and 0 comparisons when n ≤ 1.

6 Recurrences

Ernst Mayr, Harald Räcke 43

Page 167: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Recurrences

How do we bring the expression for the number of comparisons

(≈ running time) into a closed form?

For this we need to solve the recurrence.

6 Recurrences

Ernst Mayr, Harald Räcke 44/120

6 Recurrences

Algorithm 2 mergesort(listL)1: n← size(L)2: if n ≤ 1 return L3: L1 ← L[1 · · · bn

2c]

4: L2 ← L[bn2c + 1 · · ·n]

5: mergesort(L1)6: mergesort(L2)7: L←merge(L1, L2)8: return L

This algorithm requires

T(n) = T(⌈n

2

⌉)+ T

(⌊n2

⌋)+O(n) ≤ 2T

(⌈n2

⌉)+O(n)

comparisons when n > 1 and 0 comparisons when n ≤ 1.

6 Recurrences

Ernst Mayr, Harald Räcke 43

Page 168: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Methods for Solving Recurrences

1. Guessing+Induction

Guess the right solution and prove that it is correct via

induction. It needs experience to make the right guess.

2. Master Theorem

For a lot of recurrences that appear in the analysis of

algorithms this theorem can be used to obtain tight

asymptotic bounds. It does not provide exact solutions.

3. Characteristic Polynomial

Linear homogenous recurrences can be solved via this

method.

6 Recurrences

Ernst Mayr, Harald Räcke 45/120

Recurrences

How do we bring the expression for the number of comparisons

(≈ running time) into a closed form?

For this we need to solve the recurrence.

6 Recurrences

Ernst Mayr, Harald Räcke 44

Page 169: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Methods for Solving Recurrences

4. Generating Functions

A more general technique that allows to solve certain types

of linear inhomogenous relations and also sometimes

non-linear recurrence relations.

5. Transformation of the Recurrence

Sometimes one can transform the given recurrence relations

so that it e.g. becomes linear and can therefore be solved

with one of the other techniques.

6 Recurrences

Ernst Mayr, Harald Räcke 46/120

Methods for Solving Recurrences

1. Guessing+Induction

Guess the right solution and prove that it is correct via

induction. It needs experience to make the right guess.

2. Master Theorem

For a lot of recurrences that appear in the analysis of

algorithms this theorem can be used to obtain tight

asymptotic bounds. It does not provide exact solutions.

3. Characteristic Polynomial

Linear homogenous recurrences can be solved via this

method.

6 Recurrences

Ernst Mayr, Harald Räcke 45

Page 170: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47/120

Page 171: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47/120

Page 172: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47/120

Page 173: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d.

Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 174: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 175: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 176: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn

= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 177: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n

≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 178: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 179: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48/120

6.1 Guessing+Induction

First we need to get rid of the O-notation in our recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 2

0 otherwise

Assume that instead we had

T(n) ≤

2T(n

2

)+ cn n ≥ 2

0 otherwise

One way of solving such a recurrence is to guess a solution, and

check that it is correct by plugging it in.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 47

Page 180: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.

Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 181: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 182: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 183: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16):

true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 184: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 185: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 186: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 187: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 188: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 189: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn

= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 190: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n

≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 191: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 192: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

6.1 Guessing+Induction

Suppose we guess T(n) ≤ dn logn for a constant d. Then

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

if we choose d ≥ c.

Formally one would make an induction proof, where the above is

the induction step. The base case is usually trivial.

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 48

Page 193: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50/120

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

Page 194: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50/120

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

Page 195: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50/120

6.1 Guessing+Induction

• Note that this proves thestatement for n ∈ N≥2, as thestatement is wrong for n = 1.

• The base case is usually omitted,as it is the same for differentrecurrences.

T(n) ≤

2T(n

2

)+ cn n ≥ 16

b otw.Guess: T(n) ≤ dn logn.

Proof. (by induction)

ñ base case (2 ≤ n < 16): true if we choose d ≥ b.

ñ induction step 2 . . . n− 1→ n:

Suppose statem. is true for n′ ∈ 2, . . . , n− 1, and n ≥ 16.

We prove it for n:

T(n) ≤ 2T(n

2

)+ cn

≤ 2(dn2

logn2

)+ cn

= dn(logn− 1)+ cn= dn logn+ (c − d)n≤ dn logn

Hence, statement is true if we choose d ≥ c.

Page 196: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n)

≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 197: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 198: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 199: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 200: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn

≤ dn log( 9

16n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 201: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn

≤ dn log( 9

16n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 202: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 203: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 204: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn

≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 205: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn

≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 206: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn

≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 207: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn

≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 208: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.1 Guessing+Induction

We also make a guess of T(n) ≤ dn logn and get

T(n) ≤ 2T(⌈n

2

⌉)+ cn

≤ 2(d⌈n

2

⌉log

⌈n2

⌉)+ cn

≤ 2(d(n/2+ 1) log(n/2+ 1)

)+ cn≤ dn log

( 916n)+ 2d logn+ cn

= dn logn+ (log 9− 4)dn+ 2d logn+ cn≤ dn logn+ (log 9− 3.5)dn+ cn≤ dn logn− 0.33dn+ cn≤ dn logn

for a suitable choice of d.

⌈n2

⌉≤ n

2 + 1

n2 + 1 ≤ 9

16n

log 916n = logn+ (log 9− 4)

logn ≤ n4

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 51/120

6.1 Guessing+Induction

Why did we change the recurrence by getting rid of the ceiling?

If we do not do this we instead consider the following

recurrence:

T(n) ≤

2T(⌈n

2

⌉)+ cn n ≥ 16

b otherwise

Note that we can do this as for constant-sized inputs the running

time is always some constant (b in the above case).

6.1 Guessing+Induction

Ernst Mayr, Harald Räcke 50

Page 209: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52/120

Page 210: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.2 Master Theorem

We prove the Master Theorem for the case that n is of the form

b`, and we assume that the non-recursive case occurs for

problem size 1 and incurs cost 1.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 53/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 211: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 212: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 213: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 214: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 215: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 216: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 217: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 218: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 219: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

alogb n

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 220: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

alogb n

nlogb a

=

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

6.2 Master Theorem

Ernst Mayr, Harald Räcke 54/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 221: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.2 Master Theorem

This gives

T(n) = nlogb a +logb n−1∑i=0

aif(nbi

).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 55/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 222: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 223: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 224: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 225: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 226: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 227: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 228: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 229: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 230: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 231: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 232: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 233: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

+ 1)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

⇒ T(n) = O(nlogb a).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 56/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 234: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 235: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 236: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 237: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 238: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 239: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 240: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 241: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n) ⇒ T(n) = O(nlogb a logn).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 57/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 242: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 243: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 244: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 245: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 246: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 247: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 248: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 249: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n)≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n) ⇒ T(n) = Ω(nlogb a logn).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 58/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 250: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 251: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 252: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 253: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 254: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 255: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 256: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 257: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 258: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 259: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 260: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

⇒ T(n) = O(nlogb a logk+1n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 59/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 261: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 262: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 263: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 264: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 265: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 266: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 267: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 268: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

⇒ T(n) = Θ(f (n)).

Where did we use f(n) ≥ Ω(nlogb a+ε)?

6.2 Master Theorem

Ernst Mayr, Harald Räcke 60/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 269: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 270: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 271: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 272: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 273: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0

001001101

1

11011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 274: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0

001001101

1

11011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 275: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00

01001101

11

1011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 276: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00

01001101

11

1011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 277: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000

1001101

111

011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 278: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000

1001101

111

011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 279: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001

001101

1110

11001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 280: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001

001101

1110

11001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 281: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010

01101

11101

1001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 282: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010

01101

11101

1001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 283: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100

1101

111011

001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 284: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100

1101

111011

001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 285: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001

101

1110110

01

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 286: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001

101

1110110

01

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 287: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010011

01

11101100

1

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 288: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010011

01

11101100

1

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 289: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100110

1

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 290: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100110

1

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 291: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 292: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61/120

6.2 Master Theorem

Lemma 4

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n),k ≥ 0.

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 52

Page 293: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 294: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 295: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 296: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 297: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 298: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

0

10001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 299: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 300: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 301: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

00

00000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 302: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 303: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 304: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

000

10001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 305: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 306: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 307: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 308: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 309: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).

ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 310: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62/120

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 61

Page 311: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB × . . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 312: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB ×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 313: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

× . . .. . .

. . . . . .. . . . . .

a0an−1b0bn−1

an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 314: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . .

. . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 315: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 316: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 317: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63/120

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).6.2 Master Theorem

Ernst Mayr, Harald Räcke 62

Page 318: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 319: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 320: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 321: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 322: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 323: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 324: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 325: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 326: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 327: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64/120

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0an−1b0bn−1 an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0B0

6.2 Master Theorem

Ernst Mayr, Harald Räcke 63

Page 328: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65/120

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64

Page 329: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65/120

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64

Page 330: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65/120

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64

Page 331: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65/120

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

6.2 Master Theorem

Ernst Mayr, Harald Räcke 64

Page 332: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 333: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 334: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 335: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 336: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,

Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 337: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 338: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 339: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 340: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 341: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 342: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )A more precise

(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 343: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 344: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 345: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66/120

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

=⇒ Not better then the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 65

Page 346: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 67/120

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66

Page 347: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 67/120

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66

Page 348: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 67/120

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66

Page 349: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

6.2 Master Theorem

Ernst Mayr, Harald Räcke 67/120

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

A more precise(correct) analysiswould say thatcomputing Z1

needs timeT(n2 + 1)+O(n).

6.2 Master Theorem

Ernst Mayr, Harald Räcke 66

Page 350: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 351: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 352: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 353: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 354: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 355: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68/120

Page 356: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 357: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 358: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 359: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 360: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 361: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 362: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 363: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69/120

6.3 The Characteristic Polynomial

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

This is the general form of a linear recurrence relation of order kwith constant coefficients (c0, ck ≠ 0).

ñ T(n) only depends on the k preceding values. This means

the recurrence relation is of order k.

ñ The recurrence is linear as there are no products of T[n]’s.

ñ If f(n) = 0 then the recurrence relation becomes a linear,

homogenous recurrence relation of order k.

Note that we ignore boundary conditions for the moment.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 68

Page 364: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70/120

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69

Page 365: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70/120

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69

Page 366: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70/120

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69

Page 367: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70/120

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69

Page 368: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70/120

6.3 The Characteristic Polynomial

Observations:

ñ The solution T[1], T[2], T[3], . . . is completely determined

by a set of boundary conditions that specify values for

T[1], . . . , T [k].ñ In fact, any k consecutive values completely determine the

solution.

ñ k non-concecutive values might not be an appropriate set of

boundary conditions (depends on the problem).

Approach:

ñ First determine all solutions that satisfy recurrence relation.

ñ Then pick the right one by analyzing boundary conditions.

ñ First consider the homogenous case.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 69

Page 369: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71/120

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70

Page 370: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71/120

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70

Page 371: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71/120

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70

Page 372: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71/120

The Homogenous Case

The solution space

S =T = T[1], T[2], T[3], . . . ∣∣ T fulfills recurrence relation

is a vector space. This means that if T1,T2 ∈ S, then also

αT1 + βT2 ∈ S, for arbitrary constants α,β.

How do we find a non-trivial solution?

We guess that the solution is of the form λn, λ ≠ 0, and see what

happens. In order for this guess to fulfill the recurrence we need

c0λn + c1λn−1 + c2 · λn−2 + · · · + ck · λn−k = 0

for all n ≥ k.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 70

Page 373: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72/120

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71

Page 374: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72/120

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71

Page 375: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72/120

The Homogenous Case

Dividing by λn−k gives that all these constraints are identical to

c0λk + c1λk−1 + c2 · λk−2 + · · · + ck = 0c0λk + c1λk−1 + c2 · λk−2 + · · · + ck︸ ︷︷ ︸characteristic polynomial P[λ]

This means that if λi is a root (Nullstelle) of P[λ] then T[n] = λniis a solution to the recurrence relation.

Let λ1, . . . , λk be the k (complex) roots of P[λ]. Then, because of

the vector space property

α1λn1 +α2λn2 + · · · +αkλnk

is a solution for arbitrary values αi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 71

Page 376: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73/120

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72

Page 377: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]

α1 · λ21 + α2 · λ2

2 + · · · + αk · λ2k = T[2]

...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73/120

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72

Page 378: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]

...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73/120

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72

Page 379: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73/120

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72

Page 380: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73/120

The Homogenous Case

Lemma 5

Assume that the characteristic polynomial has k distinct roots

λ1, . . . , λk. Then all solutions to the recurrence relation are of

the form

α1λn1 +α2λn2 + · · · +αkλnk .

Proof.

There is one solution for every possible choice of boundary

conditions for T[1], . . . , T [k].

We show that the above set of solutions contains one solution

for every choice of boundary conditions.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 72

Page 381: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:λ1 λ2 · · · λkλ2

1 λ22 · · · λ2

k...

λk1 λk2 · · · λkk

α1

α2...

αk

=T[1]T[2]

...

T[k]

We show that the column vectors are linearly independent. Then

the above equation has a solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 74/120

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73

Page 382: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:λ1 λ2 · · · λkλ2

1 λ22 · · · λ2

k...

λk1 λk2 · · · λkk

α1

α2...

αk

=T[1]T[2]

...

T[k]

We show that the column vectors are linearly independent. Then

the above equation has a solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 74/120

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:

α1 · λ1 + α2 · λ2 + · · · + αk · λk = T[1]α1 · λ2

1 + α2 · λ22 + · · · + αk · λ2

k = T[2]...

α1 · λk1 + α2 · λk2 + · · · + αk · λkk = T[k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 73

Page 383: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 1 · · · 1 1λ1 λ2 · · · λk−1 λk...

......

...λk−1

1 λk−12 · · · λk−1

k−1 λk−1k

∣∣∣∣∣∣∣∣∣∣∣

=k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 75/120

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:λ1 λ2 · · · λkλ2

1 λ22 · · · λ2

k...

λk1 λk2 · · · λkk

α1

α2...

αk

=T[1]T[2]

...

T[k]

We show that the column vectors are linearly independent. Then

the above equation has a solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 74

Page 384: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 1 · · · 1 1λ1 λ2 · · · λk−1 λk...

......

...λk−1

1 λk−12 · · · λk−1

k−1 λk−1k

∣∣∣∣∣∣∣∣∣∣∣

=k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 75/120

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:λ1 λ2 · · · λkλ2

1 λ22 · · · λ2

k...

λk1 λk2 · · · λkk

α1

α2...

αk

=T[1]T[2]

...

T[k]

We show that the column vectors are linearly independent. Then

the above equation has a solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 74

Page 385: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 1 · · · 1 1λ1 λ2 · · · λk−1 λk...

......

...λk−1

1 λk−12 · · · λk−1

k−1 λk−1k

∣∣∣∣∣∣∣∣∣∣∣

=k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 75/120

The Homogenous Case

Proof (cont.).

Suppose I am given boundary conditions T[i] and I want to see

whether I can choose the α′is such that these conditions are met:λ1 λ2 · · · λkλ2

1 λ22 · · · λ2

k...

λk1 λk2 · · · λkk

α1

α2...

αk

=T[1]T[2]

...

T[k]

We show that the column vectors are linearly independent. Then

the above equation has a solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 74

Page 386: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 76/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 1 · · · 1 1λ1 λ2 · · · λk−1 λk...

......

...λk−1

1 λk−12 · · · λk−1

k−1 λk−1k

∣∣∣∣∣∣∣∣∣∣∣

=k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 75

Page 387: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 76/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 1 · · · 1 1λ1 λ2 · · · λk−1 λk...

......

...λk−1

1 λk−12 · · · λk−1

k−1 λk−1k

∣∣∣∣∣∣∣∣∣∣∣

=k∏i=1

λi ·

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 75

Page 388: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 77/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 76

Page 389: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 77/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1 · · · λk−21 λk−1

1

1 λ2 · · · λk−22 λk−1

2...

......

...1 λk · · · λk−2

k λk−1k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 76

Page 390: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=2

(λi − λ1) ·

∣∣∣∣∣∣∣∣∣1 λ2 · · · λk−3

2 λk−22

......

......

1 λk · · · λk−3k λk−2

k

∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 78/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 77

Page 391: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=2

(λi − λ1) ·

∣∣∣∣∣∣∣∣∣1 λ2 · · · λk−3

2 λk−22

......

......

1 λk · · · λk−3k λk−2

k

∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 78/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 λ1−λ1 ·1 · · · λk−21 −λ1 ·λk−3

1 λk−11 −λ1 ·λk−2

1

1 λ2−λ1 ·1 · · · λk−22 −λ1 ·λk−3

2 λk−12 −λ1 ·λk−2

2...

......

...1 λk−λ1 ·1 · · · λk−2

k −λ1 ·λk−3k λk−1

k −λ1 ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 77

Page 392: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Computing the Determinant

Repeating the above steps gives:∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·∏i>`

(λi − λ`)

Hence, if all λi’s are different, then the determinant is non-zero.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 79/120

Computing the Determinant

∣∣∣∣∣∣∣∣∣∣∣

1 0 · · · 0 0

1 (λ2 − λ1) ·1 · · · (λ2 − λ1) ·λk−32 (λ2 − λ1) ·λk−2

2...

......

...1 (λk − λ1) ·1 · · · (λk − λ1) ·λk−3

k (λk − λ1) ·λk−2k

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=2

(λi − λ1) ·

∣∣∣∣∣∣∣∣∣1 λ2 · · · λk−3

2 λk−22

......

......

1 λk · · · λk−3k λk−2

k

∣∣∣∣∣∣∣∣∣

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 78

Page 393: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80/120

Computing the Determinant

Repeating the above steps gives:∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·∏i>`

(λi − λ`)

Hence, if all λi’s are different, then the determinant is non-zero.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 79

Page 394: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80/120

Computing the Determinant

Repeating the above steps gives:∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·∏i>`

(λi − λ`)

Hence, if all λi’s are different, then the determinant is non-zero.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 79

Page 395: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80/120

Computing the Determinant

Repeating the above steps gives:∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·∏i>`

(λi − λ`)

Hence, if all λi’s are different, then the determinant is non-zero.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 79

Page 396: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80/120

Computing the Determinant

Repeating the above steps gives:∣∣∣∣∣∣∣∣∣∣∣

λ1 λ2 · · · λk−1 λkλ2

1 λ22 · · · λ2

k−1 λ2k

......

......

λk1 λk2 · · · λkk−1 λkk

∣∣∣∣∣∣∣∣∣∣∣=

k∏i=1

λi ·∏i>`

(λi − λ`)

Hence, if all λi’s are different, then the determinant is non-zero.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 79

Page 397: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81/120

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80

Page 398: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81/120

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80

Page 399: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81/120

The Homogeneous Case

What happens if the roots are not all distinct?

Suppose we have a root λi with multiplicity (Vielfachheit) at least

2. Then not only is λni a solution to the recurrence but also nλni .

To see this consider the polynomial

P[λ] · λn−k = c0λn + c1λn−1 + c2λn−2 + · · · + ckλn−k

Since λi is a root we can write this as Q[λ] · (λ− λi)2.

Calculating the derivative gives a polynomial that still has root

λi.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 80

Page 400: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82/120

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81

Page 401: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82/120

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81

Page 402: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82/120

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81

Page 403: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82/120

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81

Page 404: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82/120

This means

c0nλn−1i + c1(n− 1)λn−2

i + · · · + ck(n− k)λn−k−1i = 0

Hence,

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0︸ ︷︷ ︸

T[n]︸ ︷︷ ︸

T[n−1]︸ ︷︷ ︸

T[n−k]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 81

Page 405: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Homogeneous Case

Lemma 6

Let P[λ] denote the characteristic polynomial to the recurrence

c0T[n]+ c1T[n− 1]+ · · · + ckT[n− k] = 0

Let λi, i = 1, . . . ,m be the (complex) roots of P[λ] with

multiplicities `i. Then the general solution to the recurrence is

given by

T[n] =m∑i=1

`i−1∑j=0

αij · (njλni ) .

The full proof is omitted. We have only shown that any choice of

αij’s is a solution to the recurrence.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 83/120

The Homogeneous Case

Suppose λi has multiplicity j. We know that

c0nλni + c1(n− 1)λn−1i + · · · + ck(n− k)λn−ki = 0

(after taking the derivative; multiplying with λ; plugging in λi)

Doing this again gives

c0n2λni + c1(n− 1)2λn−1i + · · · + ck(n− k)2λn−ki = 0

We can continue j − 1 times.

Hence, n`λni is a solution for ` ∈ 0, . . . , j − 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 82

Page 406: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84/120

The Homogeneous Case

Lemma 6

Let P[λ] denote the characteristic polynomial to the recurrence

c0T[n]+ c1T[n− 1]+ · · · + ckT[n− k] = 0

Let λi, i = 1, . . . ,m be the (complex) roots of P[λ] with

multiplicities `i. Then the general solution to the recurrence is

given by

T[n] =m∑i=1

`i−1∑j=0

αij · (njλni ) .

The full proof is omitted. We have only shown that any choice of

αij’s is a solution to the recurrence.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 83

Page 407: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84/120

The Homogeneous Case

Lemma 6

Let P[λ] denote the characteristic polynomial to the recurrence

c0T[n]+ c1T[n− 1]+ · · · + ckT[n− k] = 0

Let λi, i = 1, . . . ,m be the (complex) roots of P[λ] with

multiplicities `i. Then the general solution to the recurrence is

given by

T[n] =m∑i=1

`i−1∑j=0

αij · (njλni ) .

The full proof is omitted. We have only shown that any choice of

αij’s is a solution to the recurrence.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 83

Page 408: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84/120

The Homogeneous Case

Lemma 6

Let P[λ] denote the characteristic polynomial to the recurrence

c0T[n]+ c1T[n− 1]+ · · · + ckT[n− k] = 0

Let λi, i = 1, . . . ,m be the (complex) roots of P[λ] with

multiplicities `i. Then the general solution to the recurrence is

given by

T[n] =m∑i=1

`i−1∑j=0

αij · (njλni ) .

The full proof is omitted. We have only shown that any choice of

αij’s is a solution to the recurrence.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 83

Page 409: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

Hence, the solution is of the form

α(

1+√52

)n+ β

(1−√5

2

)n

T[0] = 0 gives α+ β = 0.

T[1] = 1 gives

α(

1+√52

)+ β

(1−√5

2

)= 1

=⇒ α− β = 2√5

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 85/120

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84

Page 410: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

Hence, the solution is of the form

α(

1+√52

)n+ β

(1−√5

2

)n

T[0] = 0 gives α+ β = 0.

T[1] = 1 gives

α(

1+√52

)+ β

(1−√5

2

)= 1

=⇒ α− β = 2√5

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 85/120

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84

Page 411: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

Hence, the solution is of the form

α(

1+√52

)n+ β

(1−√5

2

)n

T[0] = 0 gives α+ β = 0.

T[1] = 1 gives

α(

1+√52

)+ β

(1−√5

2

)= 1

=⇒ α− β = 2√5

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 85/120

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84

Page 412: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

Hence, the solution is of the form

α(

1+√52

)n+ β

(1−√5

2

)n

T[0] = 0 gives α+ β = 0.

T[1] = 1 gives

α(

1+√52

)+ β

(1−√5

2

)= 1 =⇒ α− β = 2√

5

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 85/120

Example: Fibonacci Sequence

T[0] = 0

T[1] = 1

T[n] = T[n− 1]+ T[n− 2] for n ≥ 2

The characteristic polynomial is

λ2 − λ− 1

Finding the roots, gives

λ1/2 = 12±√

14+ 1 = 1

2

(1±

√5)

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 84

Page 413: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: Fibonacci Sequence

Hence, the solution is

1√5

[(1+√5

2

)n−(

1−√52

)n]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 86/120

Example: Fibonacci Sequence

Hence, the solution is of the form

α(

1+√52

)n+ β

(1−√5

2

)n

T[0] = 0 gives α+ β = 0.

T[1] = 1 gives

α(

1+√52

)+ β

(1−√5

2

)= 1 =⇒ α− β = 2√

5

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 85

Page 414: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

with f(n) ≠ 0.

While we have a fairly general technique for solving

homogeneous, linear recurrence relations the inhomogeneous

case is different.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 87/120

Example: Fibonacci Sequence

Hence, the solution is

1√5

[(1+√5

2

)n−(

1−√52

)n]

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 86

Page 415: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88/120

The Inhomogeneous Case

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

with f(n) ≠ 0.

While we have a fairly general technique for solving

homogeneous, linear recurrence relations the inhomogeneous

case is different.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 87

Page 416: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88/120

The Inhomogeneous Case

Consider the recurrence relation:

c0T(n)+ c1T(n− 1)+ c2T(n− 2)+ · · · + ckT(n− k) = f(n)

with f(n) ≠ 0.

While we have a fairly general technique for solving

homogeneous, linear recurrence relations the inhomogeneous

case is different.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 87

Page 417: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89/120

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88

Page 418: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89/120

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88

Page 419: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89/120

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88

Page 420: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89/120

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88

Page 421: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89/120

The Inhomogeneous Case

The general solution of the recurrence relation is

T(n) = Th(n)+ Tp(n) ,

where Th is any solution to the homogeneous equation, and Tpis one particular solution to the inhomogeneous equation.

There is no general method to find a particular solution.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 88

Page 422: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0

λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90/120

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89

Page 423: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90/120

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89

Page 424: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90/120

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89

Page 425: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90/120

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89

Page 426: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90/120

The Inhomogeneous Case

Example:

T[n] = T[n− 1]+ 1 T[0] = 1

Then,

T[n− 1] = T[n− 2]+ 1 (n ≥ 2)

Subtracting the first from the second equation gives,

T[n]− T[n− 1] = T[n− 1]− T[n− 2] (n ≥ 2)

or

T[n] = 2T[n− 1]− T[n− 2] (n ≥ 2)

I get a completely determined recurrence if I add T[0] = 1 and

T[1] = 2.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 89

Page 427: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 428: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 429: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 430: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 431: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 432: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

The Inhomogeneous Case

Example: Characteristic polynomial:

λ2 − 2λ+ 1 = 0λ2 − 2λ+ 1︸ ︷︷ ︸(λ−1)2

Then the solution is of the form

T[n] = α1n + βn1n = α+ βn

T[0] = 1 gives α = 1.

T[1] = 2 gives 1+ β = 2 =⇒ β = 1.

6.3 The Characteristic Polynomial

Ernst Mayr, Harald Räcke 90

Page 433: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 434: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 435: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 436: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 437: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 438: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Shift:

T[n− 1] = 2T[n− 2]− T[n− 3]+ 2(n− 1)− 1

= 2T[n− 2]− T[n− 3]+ 2n− 3

Difference:

T[n]− T[n− 1] =2T[n− 1]− T[n− 2]+ 2n− 1

− 2T[n− 2]+ T[n− 3]− 2n+ 3

T[n] = 3T[n− 1]− 3T[n− 2]+ T[n− 3]+ 2

and so on...

The Inhomogeneous CaseIf f(n) is a polynomial of degree r this method can be applied

r + 1 times to obtain a homogeneous equation:

T[n] = T[n− 1]+n2

Shift:

T[n− 1] = T[n− 2]+ (n− 1)2 = T[n− 2]+n2 − 2n+ 1

Difference:

T[n]− T[n− 1] = T[n− 1]− T[n− 2]+ 2n− 1

T[n] = 2T[n− 1]− T[n− 2]+ 2n− 1

Page 439: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Definition 7 (Generating Function)

Let (an)n≥0 be a sequence. The corresponding

ñ generating function (Erzeugendenfunktion) is

F(z) :=∑n≥0

anzn;

ñ exponential generating function (exponentielle

Erzeugendenfunktion) is

F(z) =∑n≥0

ann!zn.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 93/120

Page 440: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Definition 7 (Generating Function)

Let (an)n≥0 be a sequence. The corresponding

ñ generating function (Erzeugendenfunktion) is

F(z) :=∑n≥0

anzn;

ñ exponential generating function (exponentielle

Erzeugendenfunktion) is

F(z) =∑n≥0

ann!zn.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 93/120

Page 441: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94/120

6.4 Generating Functions

Definition 7 (Generating Function)

Let (an)n≥0 be a sequence. The corresponding

ñ generating function (Erzeugendenfunktion) is

F(z) :=∑n≥0

anzn;

ñ exponential generating function (exponentielle

Erzeugendenfunktion) is

F(z) =∑n≥0

ann!zn.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 93

Page 442: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94/120

6.4 Generating Functions

Definition 7 (Generating Function)

Let (an)n≥0 be a sequence. The corresponding

ñ generating function (Erzeugendenfunktion) is

F(z) :=∑n≥0

anzn;

ñ exponential generating function (exponentielle

Erzeugendenfunktion) is

F(z) =∑n≥0

ann!zn.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 93

Page 443: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 444: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 445: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 446: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 447: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 448: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 449: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 450: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95/120

6.4 Generating Functions

Example 8

1. The generating function of the sequence (1,0,0, . . .) is

F(z) = 1 .

2. The generating function of the sequence (1,1,1, . . .) is

F(z) = 11− z .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 94

Page 451: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96/120

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95

Page 452: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96/120

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95

Page 453: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96/120

6.4 Generating Functions

There are two different views:

A generating function is a formal power series (formale

Potenzreihe).

Then the generating function is an algebraic object.

Let f =∑n≥0 anzn and g =∑n≥0 bnzn.

ñ Equality: f and g are equal if an = bn for all n.

ñ Addition: f + g :=∑n≥0(an + bn)zn.

ñ Multiplication: f · g :=∑n≥0 cnzn with cn =∑np=0 apbn−p.

There are no convergence issues here.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 95

Page 454: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97/120

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96

Page 455: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97/120

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96

Page 456: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97/120

6.4 Generating Functions

The arithmetic view:

We view a power series as a function f : C→ C.

Then, it is important to think about convergence/convergence

radius etc.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 96

Page 457: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98/120

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97

Page 458: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98/120

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97

Page 459: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98/120

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97

Page 460: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98/120

6.4 Generating Functions

What does∑n≥0 zn = 1

1−z mean in the algebraic view?

It means that the power series 1− z and the power series∑n≥0 zn are invers, i.e.,

(1− z

)·( ∞∑n≥0

zn)= 1 .

This is well-defined.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 97

Page 461: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99/120

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98

Page 462: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99/120

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98

Page 463: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99/120

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98

Page 464: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99/120

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98

Page 465: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99/120

6.4 Generating Functions

Suppose we are given the generating function

∑n≥0

zn = 11− z .

We can compute the derivative:

∑n≥1

nzn−1 = 1(1− z)2

∑n≥1

nzn−1

︸ ︷︷ ︸∑n≥0(n+1)zn

Hence, the generating function of the sequence an = n+ 1

is 1/(1− z)2.

Formally the derivative of a formalpower series

∑n≥0 anz

n is definedas∑n≥0 nanzn−1.

The known rules for differentiationwork for this definition. In partic-ular, e.g. the derivative of 1

1−z is1

(1−z)2 .

Note that this requires a proof if weconsider power series as algebraicobjects. However, we did not provethis in the lecture.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 98

Page 466: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.

∑n≥k

n(n− 1) · . . . · (n− k+ 1)zn−k

=∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 467: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k

=∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 468: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 469: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 470: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 471: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100/120

6.4 Generating Functions

We can repeat this

∑n≥0

(n+ 1)zn = 1(1− z)2 .

Derivative: ∑n≥1

n(n+ 1)zn−1 = 2(1− z)3

∑n≥1

n(n+ 1)zn−1

︸ ︷︷ ︸∑n≥0(n+1)(n+2)zn

Hence, the generating function of the sequence

an = (n+ 1)(n+ 2) is 2(1−z)3 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 99

Page 472: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101/120

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100

Page 473: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101/120

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100

Page 474: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101/120

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100

Page 475: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101/120

6.4 Generating Functions

Computing the k-th derivative of∑zn.∑

n≥kn(n− 1) · . . . · (n− k+ 1)zn−k =

∑n≥0

(n+ k) · . . . · (n+ 1)zn

= k!(1− z)k+1 .

Hence: ∑n≥0

(n+ kk

)zn = 1

(1− z)k+1 .

The generating function of the sequence an =(n+kk

)is 1(1−z)k+1 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 100

Page 476: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102/120

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101

Page 477: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102/120

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101

Page 478: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102/120

6.4 Generating Functions

∑n≥0

nzn =∑n≥0

(n+ 1)zn −∑n≥0

zn

= 1(1− z)2 −

11− z

= z(1− z)2

The generating function of the sequence an = n is z(1−z)2 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 101

Page 479: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z)

=∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 480: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 481: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 482: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 483: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 484: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 485: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103/120

6.4 Generating Functions

We know ∑n≥0

yn = 11−y

Hence,

∑n≥0

anzn = 11− az

The generating function of the sequence fn = an is 11−az .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 102

Page 486: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn =

A(z) = 1(1− z)2

=∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104/120

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103

Page 487: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn =

A(z) = 1(1− z)2

=∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104/120

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103

Page 488: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2

=∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104/120

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103

Page 489: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104/120

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103

Page 490: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104/120

Example: an = an−1 + 1, a0 = 1Suppose we have the recurrence an = an−1 + 1 for n ≥ 1 and

a0 = 1.

A(z) =∑n≥0

anzn

= a0 +∑n≥1

(an−1 + 1)zn

= 1+ z∑n≥1

an−1zn−1 +∑n≥1

zn

= z∑n≥0

anzn +∑n≥0

zn

= zA(z)+∑n≥0

zn

= zA(z)+ 11− z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 103

Page 491: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 492: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− z

n+ 11

(1− z)2(n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 493: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2

(n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 494: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 495: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 496: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− az

n2z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 497: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 498: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105/120

Example: an = an−1 + 1, a0 = 1

Solving for A(z) gives

∑n≥0

anzn = A(z) = 1(1− z)2 =

∑n≥0

(n+ 1)zn

Hence, an = n+ 1.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 104

Page 499: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 500: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 501: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G

∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 502: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 503: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 504: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 505: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 506: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106/120

Some Generating Functions

n-th sequence element generating function

11

1− zn+ 1

1(1− z)2(

n+kk

) 1(1− z)k+1

n z(1− z)2

an1

1− azn2

z(1+ z)(1− z)3

1n! ez

6.4 Generating Functions

Ernst Mayr, Harald Räcke 105

Page 507: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 508: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 509: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 510: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 511: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 512: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)

ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 513: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 514: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107/120

Some Generating Functions

n-th sequence element generating function

cfn cF

fn + gn F +G∑ni=0 fign−i F ·G

fn−k (n ≥ k); 0 otw. zkF

∑ni=0 fi

F(z)1− z

nfn zdF(z)

dz

cnfn F(cz)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 106

Page 515: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 516: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 517: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 518: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 519: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 520: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108/120

Solving Recursions with Generating Functions

1. Set A(z) =∑n≥0 anzn.

2. Transform the right hand side so that boundary condition

and recurrence relation can be plugged in.

3. Do further transformations so that the infinite sums on the

right hand side can be replaced by A(z).

4. Solving for A(z) gives an equation of the form A(z) = f(z),where hopefully f(z) is a simple function.

5. Write f(z) as a formal power series.Techniques:

ñ partial fraction decomposition (Partialbruchzerlegung)ñ lookup in tables

6. The coefficients of the resulting power series are the an.

6.4 Generating Functions

Ernst Mayr, Harald Räcke 107

Page 521: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 522: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 523: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 524: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 525: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 526: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 527: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 528: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109/120

Example: an = 2an−1, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

2. Transform right hand side so that recurrence can be

plugged in:

A(z) = a0 +∑n≥1

anzn

2. Plug in:

A(z) = 1+∑n≥1

(2an−1)zn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 108

Page 529: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

5. Rewrite f(z) as a power series:

∑n≥0

anzn =

A(z) = 11− 2z

=∑n≥0

2nzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 110/120

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109

Page 530: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

5. Rewrite f(z) as a power series:

∑n≥0

anzn = A(z) = 11− 2z

=∑n≥0

2nzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 110/120

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109

Page 531: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 2an−1, a0 = 1

5. Rewrite f(z) as a power series:

∑n≥0

anzn = A(z) = 11− 2z

=∑n≥0

2nzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 110/120

Example: an = 2an−1, a0 = 1

3. Transform right hand side so that infinite sums can be

replaced by A(z) or by simple function.

A(z) = 1+∑n≥1

(2an−1)zn

= 1+ 2z∑n≥1

an−1zn−1

= 1+ 2z∑n≥0

anzn

= 1+ 2z ·A(z)

4. Solve for A(z).

A(z) = 11− 2z

6.4 Generating Functions

Ernst Mayr, Harald Räcke 109

Page 532: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111/120

Example: an = 2an−1, a0 = 1

5. Rewrite f(z) as a power series:

∑n≥0

anzn = A(z) = 11− 2z

=∑n≥0

2nzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 110

Page 533: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111/120

Example: an = 2an−1, a0 = 1

5. Rewrite f(z) as a power series:

∑n≥0

anzn = A(z) = 11− 2z

=∑n≥0

2nzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 110

Page 534: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 535: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 536: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 537: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 538: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 539: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 540: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112/120

Example: an = 3an−1 + n, a0 = 1

1. Set up generating function:

A(z) =∑n≥0

anzn

6.4 Generating Functions

Ernst Mayr, Harald Räcke 111

Page 541: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2

= z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113/120

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112

Page 542: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2

= z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113/120

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112

Page 543: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2

= z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113/120

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112

Page 544: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113/120

Example: an = 3an−1 + n, a0 = 1

2./3. Transform right hand side:

A(z) =∑n≥0

anzn

= a0 +∑n≥1

anzn

= 1+∑n≥1

(3an−1 +n)zn

= 1+ 3z∑n≥1

an−1zn−1 +∑n≥1

nzn

= 1+ 3z∑n≥0

anzn +∑n≥0

nzn

= 1+ 3zA(z)+ z(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 112

Page 545: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 546: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 547: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 548: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 549: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 550: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114/120

Example: an = 3an−1 + n, a0 = 1

4. Solve for A(z):

A(z) = 1+ 3zA(z)+ z(1− z)2

gives

A(z) = (1− z)2 + z(1− 3z)(1− z)2 =

z2 − z + 1(1− 3z)(1− z)2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 113

Page 551: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114

Page 552: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

We use partial fraction decomposition:

z2 − z + 1(1− 3z)(1− z)2

!= A1− 3z

+ B1− z +

C(1− z)2

This gives

z2 − z + 1 = A(1− z)2 + B(1− 3z)(1− z)+ C(1− 3z)

= A(1− 2z + z2)+ B(1− 4z + 3z2)+ C(1− 3z)

= (A+ 3B)z2 + (−2A− 4B − 3C)z + (A+ B + C)

6.4 Generating Functions

Ernst Mayr, Harald Räcke 114

Page 553: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z)

= 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 554: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z) = 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 555: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z) = 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 556: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z) = 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 557: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z) = 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 558: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

A(z) = 74· 1

1− 3z− 1

4· 1

1− z −12· 1(1− z)2

= 74·∑n≥0

3nzn − 14·∑n≥0

zn − 12·∑n≥0

(n+ 1)zn

=∑n≥0

(74· 3n − 1

4− 1

2(n+ 1)

)zn

=∑n≥0

(74· 3n − 1

2n− 3

4

)zn

6. This means an = 743n − 1

2n− 34 .

6.4 Generating Functions

Ernst Mayr, Harald Räcke 116/120

Example: an = 3an−1 + n, a0 = 1

5. Write f(z) as a formal power series:

This leads to the following conditions:

A+ B + C = 1

2A+ 4B + 3C = 1

A+ 3B = 1

which gives

A = 74B = −1

4C = −1

2

6.4 Generating Functions

Ernst Mayr, Harald Räcke 115

Page 559: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 560: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 561: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 562: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 563: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 564: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117/120

Page 565: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118/120

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117

Page 566: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118/120

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117

Page 567: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118/120

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117

Page 568: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118/120

6.5 Transformation of the Recurrence

Example 9f0 = 1

f1 = 2

fn = fn−1 · fn−2 for n ≥ 2 .

Define

gn := logfn .

Then

gn = gn−1 + gn−2 for n ≥ 2

g1 = log 2 = 1(for log = log2), g0 = 0

gn = Fn (n-th Fibonacci number)

fn = 2Fn

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 117

Page 569: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 570: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 571: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 572: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 573: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 574: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 575: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 576: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119/120

6.5 Transformation of the Recurrence

Example 10

f1 = 1

fn = 3fn2+n; for n = 2k, k ≥ 1 ;

Define

gk := f2k .

Then:

g0 = 1

gk = 3gk−1 + 2k, k ≥ 1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 118

Page 577: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Let n = 2k:

gk = 3k+1 − 2k+1, hence

fn = 3 · 3k − 2 · 2k

= 3(2log 3)k − 2 · 2k

= 3(2k)log 3 − 2 · 2k

= 3nlog 3 − 2n .

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 120/120

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119

Page 578: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Let n = 2k:

gk = 3k+1 − 2k+1, hence

fn = 3 · 3k − 2 · 2k

= 3(2log 3)k − 2 · 2k

= 3(2k)log 3 − 2 · 2k

= 3nlog 3 − 2n .

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 120/120

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119

Page 579: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Let n = 2k:

gk = 3k+1 − 2k+1, hence

fn = 3 · 3k − 2 · 2k

= 3(2log 3)k − 2 · 2k

= 3(2k)log 3 − 2 · 2k

= 3nlog 3 − 2n .

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 120/120

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119

Page 580: Efficient Algorithms and Data Structures · Part I Organizational Matters æ Modul: IN2003 æ Name: “Efficient Algorithms and Data Structures” “Effiziente Algorithmen und Datenstrukturen”

6 Recurrences

Let n = 2k:

gk = 3k+1 − 2k+1, hence

fn = 3 · 3k − 2 · 2k

= 3(2log 3)k − 2 · 2k

= 3(2k)log 3 − 2 · 2k

= 3nlog 3 − 2n .

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 120/120

6 Recurrences

We get

gk = 3[gk−1

]+ 2k

= 3[3gk−2 + 2k−1

]+ 2k

= 32 [gk−2]+ 32k−1 + 2k

= 32[3gk−3 + 2k−2

]+ 32k−1 + 2k

= 33gk−3 + 322k−2 + 32k−1 + 2k

= 2k ·k∑i=0

(32

)i

= 2k · (32)k+1 − 11/2

= 3k+1 − 2k+1

6.5 Transformation of the Recurrence

Ernst Mayr, Harald Räcke 119