Docsity

Master Theorem and Sorting Algorithms: Quicksort, Selection, and Radix Sort, Lecture notes of Computer Science

Partial preview of the text

Download Master Theorem and Sorting Algorithms: Quicksort, Selection, and Radix Sort and more Lecture notes Computer Science in PDF only on Docsity!

More Master Theorem, Quicksort,

Comparison Sorting, Radix Sort

Pacing?

A. Please speed up! B. I could go a bit faster C. I’m just keeping up D. A little slower would help E. Please slow down!

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

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

Quicksort(S)

 If (S has one element) return S

 Pick pivot, v

 Construct 3 lists, S (^) L, SV, SR

 SL = Quicksort(S (^) L)

 SR = Quicksort(S (^) R )

 Return(S (^) L,S (^) V,S (^) R ) append now-sorted lists

Sorting speed

A. O(2n) B. O(n^2 ) C. O(n log n) D. O(n)

Sorting speed

A. Omega(1) B. Omega(log n) C. Omega(n) D. Omega(n log n) E. Omega(n^2 )

RadixSort(list)

 for place = least to most significant

 for item in list

 calculate “digit” in item at place

 add item to end of sublist[digit]

 append all sublists back into list

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)

Master Theorem and Sort Board

Sort Lower-bound Board