You are on page 1of 31

expected run time of quicksort

run time = number of comparisons


product of probability spaces

𝐴,𝐵⊆𝑆 independent iff 𝑝 ( 𝐴 ∩ 𝐵)=𝑝 ( 𝐴) ⋅ 𝑝 ( 𝐵)

single coin flip or single throw of dice:


too simple for example

let’s consider two experiments

𝑊 1 =( 𝑆1 , 𝑝1 ) ,𝑊 2=(𝑆 2 , 𝑝 2)

set of outcomes for the pair of events

𝑆= 𝑆1 × 𝑆 2={(𝑎 , 𝑏)∨𝑎 ∈ 𝑆1 , 𝑏 ∈ 𝑆2 }

𝑝 (𝑎 , 𝑏)=𝑝 1 (𝑎 )⋅ 𝑝 2 (𝑏)

𝑊 =𝑊 1 × 𝑊 2=(𝑆 , 𝑝)
random variables from different independent experiments

𝑊 =(𝑆 , 𝑝) probability space

random variable

expected value of random variable X

𝐸 ( 𝑋 )=Σ 𝑎 ∈ 𝑆 𝑋 (𝑎 )⋅ 𝑝 ( 𝑎)

sum if we perform independent experiments


𝑊 =(𝑆 , 𝑝) probability space sanity check 1
random variable
first experiment: 𝑊 𝑆 =(𝑆 , 𝑝)
expected value of random variable X
second experiments: 𝑊 𝑖 =( 𝑅𝑖 , 𝑝 𝑖 ) 𝑖∈𝑆

𝐸 ( 𝑋 )=Σ 𝑎 ∈ 𝑆 𝑋 (𝑎 )⋅ 𝑝 ( 𝑎)

probability space: 𝑊 𝑄 =(𝑄 , 𝑞)


probability of B given A
𝑄= ⋃ {𝑖}× 𝑅𝑖
𝑖∈𝑆
𝐴 , 𝐵 ⊆ 𝑆 ,𝑝 ( 𝐴 )≠ 0
𝑎 ∈ 𝑅𝑖 → 𝑞(𝑖 , 𝑎 )=𝑝 (𝑖) ⋅ 𝑝𝑖 (𝑎)

𝑝( 𝐵∩ 𝐴)
𝑝 (𝐵∨ 𝐴)=
𝑝 ( 𝐴)

two experiments:

• throw coin
• if 0 throw coin c, otherwise dice d
• expected total number of points
it might be

𝐸 (𝑐)+1/ 2 ⋅ 𝐸 (𝑐)+1/ 2 ⋅ 𝐸 (𝑑 )=1/ 2+1 / 4 +7/ 4


random variables on these spaces
first experiment: 𝑊 𝑆 =(𝑆 , 𝑝)

second experiments: 𝑊 𝑖 =( 𝑅𝑖 , 𝑝 𝑖 ) 𝑖∈𝑆

probability space: 𝑊 𝑄 =(𝑄 , 𝑞)

𝑄= ⋃ {𝑖}× 𝑅𝑖
𝑖∈𝑆

𝑎 ∈ 𝑅𝑖 → 𝑞(𝑖 , 𝑎 )=𝑝 (𝑖) ⋅ 𝑝𝑖 (𝑎)

two experiments:

• throw coin
• if 0 throw coin c, otherwise dice d
• expected total number of points

𝐸 (𝑐)+1/ 2 ⋅ 𝐸 (𝑐)+1/ 2 ⋅ 𝐸 (𝑑 )=1/ 2+1 / 4 +7/ 4


Quicksort
here: the algorithm does the random experiments

input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) } we assume here: a(i) mutually distinct

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 }

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


𝑊 1 =( 𝑆1 , 𝑝1 ) ,𝑊 2=(𝑆 2 , 𝑝 2)
first experiment: 𝑊 𝑆 =(𝑆 , 𝑝)
𝑝 (𝑎 , 𝑏)=𝑝 1 (𝑎 )⋅ 𝑝 2 (𝑏)
second experiments: 𝑊 𝑖 =( 𝑅𝑖 , 𝑝 𝑖 ) 𝑖∈𝑆

𝑊 =𝑊 1 × 𝑊 2=(𝑆 , 𝑝)

probability space: 𝑊 𝑄 =(𝑄 , 𝑞)

𝑄= ⋃ {𝑖}× 𝑅𝑖
𝑖∈𝑆

𝑎 ∈ 𝑅𝑖 → 𝑞(𝑖 , 𝑎 )=𝑝 (𝑖) ⋅ 𝑝𝑖 (𝑎)

𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 )

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1

rank of splitter s: number of a(i)≤ s.


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑝 (𝑖)=1 /𝑛 𝑊 =(𝑆𝑛 , 𝑝 ) is probability space.

rank of splitter s: number of a(i)≤ s.


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )

𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)

𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛

𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )

𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)

𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛

𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)

𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛

𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
proof: induction on n.
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) n = 0 or 1: trivial
𝑖∈ 𝑆𝑛

𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
proof: induction on n.
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) • n = 0 or 1: trivial
𝑖∈ 𝑆𝑛
• assume true for j<n:
𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
proof: induction on n. 𝑖 − 1<𝑛 , 𝑛 − 𝑖<𝑛 Lemma 1: is probability space
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) • n = 0 or 1: trivial
𝑖∈ 𝑆𝑛
• assume true for j<n:
𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
proof: induction on n. 𝑖 − 1<𝑛 , 𝑛 − 𝑖<𝑛 Lemma 1: is probability space
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) • n = 0 or 1: trivial
𝑖∈ 𝑆𝑛 Lemma 10: is probability space
• assume true for j<n:
𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) number of comparisons, random variable on
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) defined by induction on
𝑖∈ 𝑆𝑛

𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)


Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on

random variable on
𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on Lemma 9:

random variable on
𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on Lemma 9:

random variable on Lemma 12:


𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
Define by induction on n probability spaces for sorting
n distinct numbers
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }


and random variables
all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }


𝑛 ∈ {0 , 1 }: 𝑄𝑛 ={⊥ } 𝑞𝑛 (⊥)=1 𝑡 𝑛 (⊥)=0

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )


0 or 1 elements: no randomness
no comparisons
𝑛≥2: 𝑆 𝑛= {1 , … 𝑛 } 𝑖 ∈ 𝑆𝑛 𝑖=¿ 𝐴 ¿ +1 𝑟 𝑛 (𝑖)=1/ 𝑛 𝑊 =(𝑆𝑛 , 𝑟 𝑛 ) is probability space.

𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on Lemma 9:

random variable on Lemma 12:


𝑞𝑛 (𝑖 ,(𝑎 , 𝑏))=(1 /𝑛) ⋅ 𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))
back to the sixties!!!

Lemma:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))
back to the sixties!!!

Lemma:

proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))

Lemma:

proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))

Lemma:

proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))

Lemma:

proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }

random experiment: choose ‚splitter‘ 𝑠 ∈{𝑎 (1), … , 𝑎 (𝑛) }

all n splitters equally likely

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 < 𝑠 } a(i) mutually distinct

𝐴 ¿ ={𝑎 ∈ 𝐴∨𝑎 > 𝑠 }

𝑠𝑜𝑟𝑡 ( 𝐴)=𝑠𝑜𝑟𝑡 ( 𝐴 ¿ ) ∘ 𝑠 ∘ 𝑠𝑜𝑟𝑡 ( 𝐴 ¿ )

𝑇 (𝑛)= 𝐸 (𝑡 𝑛 ) : 𝑇 (𝑛)=𝑛 − 1+(1/ 𝑛) ⋅ Σ 𝑛


𝑖=1 (𝑇 (𝑖 − 1)+𝑇 (𝑛 − 𝑖))

Lemma:

proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:

You might also like