Algorithm Analysis (CSC 301 2015F) : EBoards

CSC301.01 2015F, Class 05: Divide and Conquer Approaches


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit

Academic

Peer

Questions

Divide and Conquer Algorithms

Basic strategy

What divide and conquer algorithms do you already know?

Analyzing Divide-and-Conquer Algorithms

How do we normally analyze algorithms (informally)

Will this strategy work for divide and conquer?

    define Quicksort(A)
      if (small(A))
        return
      else
        partition(A)
        Quicksort(firsthalf(A))
        Quicksort(secondhalf(A))

In general, we write equations to carefully specify the cost. Merge sort

    define mergesort(A)
      if (oneelement(A))
        return
      merge(sort(firsthalf(A)),sort(secondhalf(A)))

    T(n) is supposed to be "bound on steps to sort an array
    of size n using mergesort"

    T(1) = 1
    T(n) = T(n/2) ; sort(firsthalf(A))
           + T(n/2) ; sort(secondhalf(A))
           + Theta(n) ; merge

As mathematicians, we'd like to find an exact bound for that function. (As computer scientists, we're okay with an extra constant multiplier.) How do we do so?

Estimating Recurrence Relations

    T(n) <= 2*T(n/2) + c*n
    T(1) = 1

Top-down expansion

Look at the main results

    T(n) <= 2*T(n/2) + c*n
         <= 4*T(n/4) + 2*c*n 
         <= 8*T(n/8) + 3cn
         <= 16*T(n/16) + 4cn
         <= 2^k*T(n/2^k) + k*c*n

Solve for 2^k = n; k = log_2(n)

        <= n*T(1) + log_2(n)*c*n
        <= 1 + c*n*log_2(n)

Bottom-up expansion

Solving Recurrence Relations with Recursion Trees

    T(n) = 3*T(n/4) + Theta(n^2)

Proving Recurrence Relations with the Substitution Method

Solving Recurrence Relations with the Master Theorem