cs 312 algorithm analysis n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CS 312: Algorithm Analysis PowerPoint Presentation
Download Presentation
CS 312: Algorithm Analysis

Loading in 2 Seconds...

play fullscreen
1 / 28

CS 312: Algorithm Analysis - PowerPoint PPT Presentation


  • 77 Views
  • Uploaded on

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License . CS 312: Algorithm Analysis. Lecture #9: Solving Divide and Conquer Recurrence Relations with Change of Variable. Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CS 312: Algorithm Analysis' - kalani


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cs 312 algorithm analysis

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

CS 312: Algorithm Analysis

Lecture #9: Solving Divide and Conquer Recurrence Relations with Change of Variable

Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick

announcements
Announcements
  • HW #6 Due Today
    • Questions about Non-homogeneous RR?
  • Project #2
    • Questions?
    • Early Day: Wednesday
    • Due: Friday
objectives
Objectives
  • Understand how to analyze recurrence relations that are typical of divide and conquer algorithms
  • Learn to use the “change of variable” technique to solve such recurrences
  • Review Merge sort (quickly!)
    • Theoretical analysis using RRs
  • Time permitting, prove the Master theorem
analysis approach reduction
Analysis Approach: Reduction

Divide and Conquer Recurrence Relation

Change of Variable

Non-Homogeneous Recurrence Relation with Geometric Forcing Function

LTI Homogeneous Recurrence Relation

analysis approach reduction1
Analysis Approach: Reduction

Divide and Conquer Recurrence Relation

Change of Variable

Non-Homogeneous Recurrence Relation with Geometric Forcing Function

“Unwindthe Stack”

LTI Homogeneous Recurrence Relation

review merge sort

3

1

4

1

5

9

2

6

5

3

5

8

9

3

1

4

1

5

9

2

6

5

3

5

8

9

2

3

5

5

6

8

9

1

1

3

4

5

9

1

1

2

3

3

4

5

5

5

6

8

9

9

Review: Merge sort
  • Split the array in 1/2
  • Sort each 1/2
  • Merge the sorted halves
  • Adhoc(): Use insertion sort when sub-arrays are small
analysis of merge

3

1

4

1

5

9

2

6

5

3

5

8

9

3

1

4

1

5

9

2

6

5

3

5

8

9

2

3

5

5

6

8

9

1

1

3

4

5

9

1

1

2

3

3

4

5

5

5

6

8

9

9

Analysis of merge()

proceduremerge (U[1..p+1], V[1..q+1], A[1..n])

i,j 1

U[p+1],V[q+1]  sentinel

for k  1 top+qdo

if U[i] < V[ j]

then A[k]  U[i]; i  i + 1

else A[k]  V[j]; j  j + 1

How long to merge?

U

V

A

merge sort
Merge sort

proceduremergesort (A[1..n])

if n is small enough theninsertsort (A)

else

array U[1..1+floor(n/2)], V[1..1+ceil(n/2)]

U[1..floor(n/2)]  A[1..floor(n/2)]

V[1..ceil(n/2)]  A[1+floor(n/2)..n]

mergesort (U)

mergesort (V)

merge (U,V,A)

What is the efficiency of Mergesort?

using the master theorem
Using the Master Theorem

a = number of sub-instances that must be solved

n = original instance size (variable)

n/b = size of subinstances

d = polynomial order of g(n),

where g(n) = cost of dividing and recombining

another useful logarithm identity
Another Useful Logarithm Identity

Proof:

Statement Reason

  • and are inverses
  • commutativity of
  • and are inverses
assignment
Assignment
  • Read: Section 2.3 in the textbook
  • HW #7:
    • Part III Exercises (Section 3.2)
    • Analyze 3-part mergesort using recurrence relations techniques
    • Problem 2.4 in the textbook (using the master theorem where possible)