Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Average Case Analysis of Quicksort: Probability of Adjustments and Comparisons - Prof. Mic, Study notes of Algorithms and Programming

A lecture note from a university course on algorithm design and analysis, focusing on the average case analysis of quicksort. The instructor, mike kowalczyk, discusses the probability of adjustments during seating analogy and its connection to quicksort. The document also includes a recurrence relation for the average number of comparisons in quicksort and proves that it does θ(n lg n) comparisons on average.

Typology: Study notes

Pre 2010

Uploaded on 08/01/2009

koofers-user-a80
koofers-user-a80 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Average Case Analysis of Quicksort: Probability of Adjustments and Comparisons - Prof. Mic and more Study notes Algorithms and Programming in PDF only on Docsity! Algorithm Design and Analysis 2/23/2008 Lecture 18 - Average case analysis of Quicksort Instructor: Mike Kowalczyk 1 Analysis of the random usher, and the connection to Quicksort (This lecture is a continuation of lecture 16) Suppose we have k people seated already in a row of n people, and we seat the next person. What’s the probability that some fixed person who’s already seated has to adjust? The probability will be 1n−k if that person has “contiguous seating to one end”, and 2 n−k otherwise. How many adjustments do we expect to see overall? One upper bound is to say on each seating, there can be at most k adjustments, when there’s k people already seated. This leads us to ∑n−1 k=0 k = Θ(n 2) adjustments in the worst case. More precisely, if there’s k people already seated, and 2n−k chance of each getting adjusted (using the worst case here), then total number of expected adjustments is 2kn−k . To find the total adjustments overall, we can just use a summation. Note that the second equality below holds by reversing the series (write out both series longhand to convince yourself that the second step is correct). n−1∑ k=0 2k n− k = 2 n−1∑ k=1 k n− k = 2 n−1∑ k=1 n− k k = 2 n−1∑ k=1 (n k − 1 ) = −2(n− 1) + 2 n−1∑ k=1 n k = −2(n− 1) + 2n n−1∑ k=1 1 k ∼ −2(n− 1) + 2n ∫ n−1 k=1 1 k ∼ −2n+ 2n ln(n) = θ(n lg n) So Θ(n2) steps in the worst case, and θ(n lg n) steps on average. Isn’t Quicksort supposed to have a similar behavior? Let’s take another look at Quicksort: 1
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved