Docsity

Master Theorem - Introduction to Algorithms and Data Structures - Lecture Sli, Lecture notes of Computer Science

Partial preview of the text

Download Master Theorem - Introduction to Algorithms and Data Structures - Lecture Sli and more Lecture notes Computer Science in PDF only on Docsity!

Master Theorem, Mergesort,

Selection, Quicksort

Testing a Queue

Q.enqueue(n)

n=Q.dequeue() # exception if empty Q.size()

Q.isEmpty()

Testing a Queue

Q.enqueue(n)

n=Q.dequeue() # exception if empty Q.size()

Q.isEmpty()

Master Theorem

Let T(n) be a monotonically increasing function that satisfies: T(n) = aT(n/b) + Θ(n d^ ) Where a≥1, b>1, d≥0.

T(n) is Θ(n d^ ) if a < bd T(n) is Θ(n d^ log n) if a = bd T(n) is Θ(n log a b^ ) if a > bd

a is number of sub- problems 1/b is size of sub- problems nd^ is cost within a given level

Analysis of min(unsorted list[n])

A. O(1)

B. O(log n)

C. O(sqrt(n))

D. O(n)

E. O(n log n)

Analysis of max(unsorted list[n])

A. O(1)

B. O(log n)

C. O(sqrt(n))

D. O(n)

E. O(n log n)

Selection(k, list)

 Returns k th^ smallest element in list

 Divide and conquer

Selection(k, list)

 Returns k th^ smallest element in list

 Divide and conquer

 Pick pivot, v

 Create three sub-lists

 Find which sub-list k is in from sub-list sizes

 Return Selection(k (^2) , appropriate-sub-list)

Quicksort(list)

 Pick pivot, v

 Construct 3 lists, SL, SV, SR

 Quicksort(SL)

 Quicksort(SR)

 Return(SL,SV,SR) append now-sorted lists

Genetic Algorithms (GAs)

 Search and optimization heuristic

 Mimics natural evolution  Genome for candidate solutions  Mutation, selection, inheritance, and crossover

 http://www.youtube.com/watch?v=JBgG_VSP 7f8 (example of Karl Sims)

 http://vimeo.com/ 12058493 (tribute)