Download presentation
Presentation is loading. Please wait.
Published byPaula Parrish Modified over 9 years ago
1
CS2420: Lecture 12 Vladimir Kulyukin Computer Science Department Utah State University
2
Outline Sorting Algorithms (Chapter 7)
3
QuickSort: Recurrence
4
Worst-Case Analysis In the worst case, we always pick the pivot as the smallest or largest element in the array. In this case, we break the basic recursive design principle to partition the problem into chucks of equal size. The array is reduced only by 1 element.
5
Worst-Case Analysis: Recurrence
6
QuickSort: Best-Case Analysis
7
Probability Models Suppose we want to construct a probability model of some event. In probability theory, events are typically modeled with random variables. One can think of a random variable as a variable that takes on certain values (produce certain outcomes) with certain probabilities. In modeling an event our task is to assign some random variable to an event and then figure out what outcomes the variable produces and with what probabilities.
8
A 2-Sided Coin Suppose the event we are interested in modeling is the tossing of a fair 2-sided coin. Suppose that we assigned the value of 1 to heads and the value of 2 to tails. Then our random variable, say X, will have assume two values: 1 and 2. Since we believe that the coin is fair, we can assign a probability of 0.5 to each outcome.
9
A 2-Sided Coin Outcome12 Probabili ty 0.5
10
Expected Value
11
Expected Value of the 2-Sided Fair Coin Toss
12
A Fair 6-Sided Die outco me 123456 proba bility 1/6
13
Expected Value of the Die Throw
14
QuickSort: Average-Case Analysis We assume that all sizes of the left sub- array, i.e., the values of |LEFT|, are equally likely. Do we have to worry about |RIGHT|? Not really, because |RIGHT| is a function of |LEFT|, i.e., |RIGHT| = N - |LEFT| - 1.
15
QuickSort: Average-Case Analysis The possible values of |LEFT| and |RIGHT| range from 0 to n-1. The random variables that we are interested in modeling is T(|LEFT|) and T(|RIGHT|). Now we can proceed to the probability models.
16
T(|Left|): Probability Model Outco me T(0)T(1)T(2)……T(n-1) Proba bility 1/n
17
T(|Right|): Probability Model Outco me T(0)T(1)T(2)……T(n-1) Proba bility 1/n
18
Expected Value of T(|Left|)
19
Expected Value of T(|Right|)
20
Merging Two Sorted Arrays: Probability Model OutcomeN Probability1.0
21
QuickSort: Expected Value of T(N)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.