Professional Documents
Culture Documents
I2EA-6 Analysis of Quicksort-P
I2EA-6 Analysis of Quicksort-P
𝑊 1 =( 𝑆1 , 𝑝1 ) ,𝑊 2=(𝑆 2 , 𝑝 2)
𝑆= 𝑆1 × 𝑆 2={(𝑎 , 𝑏)∨𝑎 ∈ 𝑆1 , 𝑏 ∈ 𝑆2 }
𝑝 (𝑎 , 𝑏)=𝑝 1 (𝑎 )⋅ 𝑝 2 (𝑏)
𝑊 =𝑊 1 × 𝑊 2=(𝑆 , 𝑝)
random variables from different independent experiments
random variable
𝐸 ( 𝑋 )=Σ 𝑎 ∈ 𝑆 𝑋 (𝑎 )⋅ 𝑝 ( 𝑎)
𝐸 ( 𝑋 )=Σ 𝑎 ∈ 𝑆 𝑋 (𝑎 )⋅ 𝑝 ( 𝑎)
𝑝( 𝐵∩ 𝐴)
𝑝 (𝐵∨ 𝐴)=
𝑝 ( 𝐴)
two experiments:
• throw coin
• if 0 throw coin c, otherwise dice d
• expected total number of points
it might be
𝑄= ⋃ {𝑖}× 𝑅𝑖
𝑖∈𝑆
two experiments:
• throw coin
• if 0 throw coin c, otherwise dice d
• expected total number of points
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) } we assume here: a(i) mutually distinct
𝑊 =𝑊 1 × 𝑊 2=(𝑆 , 𝑝)
𝑄= ⋃ {𝑖}× 𝑅𝑖
𝑖∈𝑆
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 )
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
proof: induction on n.
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 ) n = 0 or 1: trivial
𝑖∈ 𝑆𝑛
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 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 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on Lemma 9:
𝑄 𝑆𝑛=(𝑄 𝑛 ,𝑞 𝑛 ) 𝑅 𝑆𝑛 ,𝑖 =𝑄 𝑆𝑖 −1 ×𝑄 𝑆𝑛−𝑖
𝑅𝑛 ,𝑖 =( 𝑄𝑖 − 1 ×𝑄 𝑛 −𝑖 )
Lemma: For all i and n: and are probability spaces
𝑞𝑛 ,𝑖 ( 𝑎 , 𝑏)=𝑞𝑖 −1 ( 𝑎) ⋅ 𝑞𝑛 − 𝑖 (𝑏)
𝑡 𝑛 (𝑖 ,(𝑎 , 𝑏))=𝑛 − 1+𝑡 𝑖 −1 (𝑎)+ 𝑡 𝑛 −𝑖 (𝑏) ′
¿ 𝑛 − 1+𝑡 𝑛 , 𝑖 (𝑎 ,𝑏)
𝑄𝑛 = ⋃ {𝑖}×(𝑄𝑖−1 ×𝑄 𝑛−𝑖 )
𝑖∈ 𝑆𝑛 random variable on Lemma 9:
Lemma:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }
Lemma:
proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }
Lemma:
proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }
Lemma:
proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }
Lemma:
proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1:
input: (𝑎 (1) , … , 𝑎( 𝑛)) or set 𝐴= {𝑎 (1) ,… , 𝑎(𝑛) }
Lemma:
proof: induction on n
• n = 1: 𝑇 (1)=0=2 ⋅ 1 ln ( 1)
• n>1: