Randomized Quicksort (8.4.2/7.4.2)

1 / 7
About This Presentation
Title:

Randomized Quicksort (8.4.2/7.4.2)

Description:

Randomized Quicksort (8.4.2/7.4.2) Randomized Quicksort i = Random(p, r) swap A[p] A[i] partition A(p, r) Average analysis = Expected runtime –

Number of Views:127
Avg rating:3.0/5.0
Slides: 8
Provided by: alexz
Learn more at: http://www.cs.gsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Randomized Quicksort (8.4.2/7.4.2)


1
Randomized Quicksort (8.4.2/7.4.2)
  • Randomized Quicksort
  • i Random(p, r)
  • swap Ap ? Ai
  • partition A(p, r)
  • Average analysis Expected runtime
  • solving recurrence ? T(n) ? a? n? log n b
  • by induction, it is true for k lt n, need to show

2
Average Time Analysis
3
Min Max (10.1/9.1)
  • Given n numbers A1, ..., An, find maximum
  • at least n-1 comparisons - 1 for each entry
  • Simultaneous max and min
  • MAX
  • MIN
  • 3(n/2) comparisons

4
Selection Problem (10.2/9.2)
  • Selection Problem
  • Given n numbers A1, ..., An,
  • find i-th element, i.e. which is bigger than
    i-1
  • Can be solved by sorting (inefficient)
  • Randomized algorithm
  • randomized partition into 2 parts
  • find where the i-th element (on the left or on
    the right)
  • find the new number of the i-th in the corr. part
  • recursively repeat for the corr.part (only one
    part!)
  • Excellent in practice

5
Selection Problem (10.2/9.2)
  • Average time analysis
  • Inductive hypothesis

6
WC Linear Selection (10.3/9.3)
  • Theoretical interest only
  • How to find pseudo-median in linear time
  • divide into groups of 5
  • find the median of each group
  • find the median x of medians recursively
  • What do we find? 1 3 partition
  • Recursion T(n) T(n/5) O(n) ? T(n) O(n)

7
WC Linear Selection (10.3/9.3)
  • How to find the i-th
  • Partition n elements around pseudo-median
  • find the part containing the i-th
  • recursively continue until 5 elements left
  • Recursion
  • T(n) T(n/(4/3)) O(n) ? T(n) O(n)
  • Master method still constant
Write a Comment
User Comments (0)
About PowerShow.com