Average Case Analysis - PowerPoint PPT Presentation

About This Presentation
Title:

Average Case Analysis

Description:

Princeton University COS 423 Theory of Algorithms ... Quicksort: BST Representation of Pivots. 10. pivot elements. 7. 6. 12. 3. 8. 7. 1. 15. 5. 16. 14 ... – PowerPoint PPT presentation

Number of Views:141
Avg rating:3.0/5.0
Slides: 12
Provided by: kevin59
Category:
Tags: analysis | average | bst | case

less

Transcript and Presenter's Notes

Title: Average Case Analysis


1
Average Case Analysis
2
Beyond Worst Case Analysis
  • Worst-case analysis.
  • Analyze running time as function of worst input
    of a given size.
  • Average case analysis.
  • Analyze average running time over some
    distribution of inputs.
  • Ex quicksort.
  • Amortized analysis.
  • Worst-case bound on sequence of operations.
  • Ex splay trees, union-find.
  • Competitive analysis.
  • Make quantitative statements about online
    algorithms.
  • Ex paging, load balancing.

3
Average Case Analysis
  • Average case analysis.
  • Analyze average running time over some
    distribution of inputs.
  • Ex quicksort.
  • O(N log N) if input is assumed to be in random
    order.
  • leads to randomized algorithm with O(N log N)
    expected running time, independent of input
  • Major disadvantage hard to quantify what input
    distributions will look like in practice.

4
Quicksort
  • Quicksort.
  • Assume all elements are unique.
  • Assume input is a random permutation of inputs.
  • Denote ith largest element by i.

5
Quicksort BST Representation of Pivots
6
Quicksort Average Case Analysis
  • Probability that i 2 and j 7 get compared.
  • Let x be pivot element that separates i and j.
  • Case 1 x ? 3, 4, 5, 6 ? i and j not
    compared.

10
13
5
16
11
3
9
2
4
7
12
15
17
1
6
8
14
7
Quicksort Average Case Analysis
  • Probability that i 2 and j 7 get compared.
  • Let x be pivot element that separates i and j.
  • Case 1 x ? 3, 4, 5, 6 ? i and j not
    compared.
  • Case 2 x ? 2, 7 ? i and j are compared.

10
13
7
16
11
3
9
2
5
8
12
15
17
1
14
4
6
8
Quicksort Average Case Analysis
  • Probability that i 2 and j 7 get compared.
  • Let x be pivot element that separates i and j.
  • Case 1 x ? 3, 4, 5, 6 ? i and j not
    compared.
  • Case 2 x ? 2, 7 ? i and j are compared.

9
Quicksort Average Case Analysis
  • Quicksort average case analysis.
  • Expected of comparisons
  • Remark same analysis if we choose
    partitionelement uniformly at random.
  • Running time independent of input.

10
Comparison Based Sorting Lower Bound
a1 lt a2
YES
NO
a2 lt a3
a1 lt a3
NO
YES
YES
NO
a1 lt a3
a2 lt a3
2, 1, 3
1, 2, 3
YES
YES
NO
NO
2, 3, 1
3, 2, 1
1, 3, 2
3, 1, 2
Decision Tree of Program
11
Comparison Based Sorting Lower Bound
  • Lower bound ?(N log2N) applies to
    comparison-based algorithms.
  • Tree height h determines worst case running time.
  • N! different input orderings.
  • One (or more) leaves corresponds to each
    ordering.
  • Binary tree with N! leaves has height

Stirling's formula
Write a Comment
User Comments (0)
About PowerShow.com