Quicksort Sorting Lower Bound Exam Exam Exam Exam 2 2 tomorrow - - PDF document

quicksort sorting lower bound
SMART_READER_LITE
LIVE PREVIEW

Quicksort Sorting Lower Bound Exam Exam Exam Exam 2 2 tomorrow - - PDF document

5/7/2012 Quicksort Sorting Lower Bound Exam Exam Exam Exam 2 2 tomorrow evening 2 2 tomorrow evening tomorrow evening tomorrow evening Topics were listed in Day 24 slides Some WA9 problems are good reinforcement of exam


slide-1
SLIDE 1

5/7/2012 1

Quicksort Sorting Lower Bound

Exam

Exam Exam Exam 2 2 2 2 tomorrow evening tomorrow evening tomorrow evening tomorrow evening

  • Topics were listed in Day 24 slides
  • Some WA9 problems are good reinforcement of exam

material.

  • Nothing from that assignment will explicitly ne on the

exam.

  • Written part: 100 points
  • Computer part: 44 points (plus some extra credit)

WA9 due Thursday

WA9 due Thursday WA9 due Thursday WA9 due Thursday

Scrabble Milestone 2 due Friday

Scrabble Milestone 2 due Friday Scrabble Milestone 2 due Friday Scrabble Milestone 2 due Friday

  • 5 days since Milestone 1, 4 days until Milestone 2
  • You want to have everything except your computer player

working for Milestone 2

Agenda:

Agenda: Agenda: Agenda:

  • Questions about exam, Scrabble, anything else?
  • Quicksort improvements
  • Lower Bound for Sorting Algorithms
  • Radix Sort
slide-2
SLIDE 2

5/7/2012 2

Best, worst, average time for Quicksort What causes the worst case? Avoid the worst case

  • Select pivot from the middle
  • Randomly select pivot
  • Median of 3 pivot selection.
  • Median of k pivot selection

"Switch over" to a simpler sorting method

(insertion) when the subarray size gets small Weiss's code does Nedian of 3 and switchover to insertion sort at 10.

  • Linked from schedule page

Q1 Q1 Q1 Q1

slide-3
SLIDE 3

5/7/2012 3

http://maven.smith.edu/~thiebaut/java/sort/

demo.html

http://www.cs.ubc.ca/~harrison/Java/sorting

<demo.html

We can’t do much better than what we already know how to do.

slide-4
SLIDE 4

5/7/2012 4

Lower bound for best case? A particular algorithm that achieves this? Want a function f(N)

f(N) f(N) f(N) such that the worst case running time worst case running time worst case running time worst case running time for all sorting algorithms all sorting algorithms all sorting algorithms all sorting algorithms is > > > >( ( ( (f(N)) f(N)) f(N)) f(N))

How do we get a handle on

“all sorting algorithms”?

Tricky!

slide-5
SLIDE 5

5/7/2012 5

We can’t list all sorting algorithms and

analyze all of them

  • Why not?

But we can find a uniform

uniform uniform uniform representation representation representation representation of any sorting algorithm that is based on comparing comparing comparing comparing elements of the array to each

  • ther

This "uniform representation" idea is exploited in a big way in Theory of Computation, e.g., to demonstrate the unsolvability of the "Halting Problem"

The problem of sorting N elements is at least

as hard as determining their ordering

  • e.g., determining that a3 < a4 < a1 < a5 < a2

So any lower bound on all "order<

determination" algorithms is also a lower bound on "all sorting algorithms"

slide-6
SLIDE 6

5/7/2012 6

Let A be any comparison

comparison comparison comparison< < < <based algorithm based algorithm based algorithm based algorithm for sorting an array of distinct elements

Note: sorting is asymptotically equivalent to

determining the correct order of the originals

We can draw an EBT that corresponds to the

comparisons that will be used by A to sort an array of N elements

  • This is called a sort decision tree

sort decision tree sort decision tree sort decision tree

  • Just a pen<and<paper concept, not actually a data

structure

  • Different algorithms will have different trees

Q2 Q2 Q2 Q2

Minimum number of external nodes in a sort

decision tree? (As a function of N)

Is this number dependent on the algorithm? What’s the height of the shortest EBT with

that many external nodes?

No comparison<based sorting algorithm, known or not yet discovered, can ever ever ever ever do better than this!

Q3 Q3 Q3 Q3< < < <5 5 5 5

slide-7
SLIDE 7

5/7/2012 7

>(N log N) is the best we can do if we

compare items

Can we sort without comparing items? O(N) sort: Bucket sort

  • Works if possible values come from limited range
  • Example: Exam grades histogram

A variation: Radix sort

Q6 Q6 Q6 Q6

slide-8
SLIDE 8

5/7/2012 8

A picture is worth 103 words, but an

animation is worth 210 pictures, so we will look at one.

http://www.cs.auckland.ac.nz/software/AlgA

nim/radixsort.html Q7 Q7 Q7 Q7< < < <10 10 10 10

Used an appropriate combo of mechanical, digital, and human effort to get the job done.

slide-9
SLIDE 9

5/7/2012 9