SlideShare una empresa de Scribd logo
1 de 49
“Monte Carlo method” 
generate M random permutations of {1,…,20} 
let H be the number of those in which 
exactly one person gets his/her card back 
output H/M
Lower bounds 
number from {1,2,3,…,9} 
3 yes/no questions 
Can you always figure out the number?
Lower bounds 
number from {1,2,3,…,8} 
3 yes/no questions 
Can you always figure out the number?
Lower bounds 
number from {1,2,3,…,8} 
3 yes/no questions 
in {1,2,3,4} ? 
Y N 
in {1,2} ? in {5,6} ? 
Y 
Y N 
N 
=1 ? =3 ? =5 ? =7 ? 
Y Y Y Y 
N N 
N N 
1 2 3 4 5 6 7 8
Lower bounds 
number from {1,2,3,…,n} 
k yes/no questions
Lower bounds 
number from {1,2,3,…,n} 
k yes/no questions 
k = é log2 n ù
Lower bounds 
number from {1,2,3,…,n} 
k yes/no questions 
k = é log2 n ù 
INFORMATION THEORETIC LOWER BOUND: 
k³ log2 n
Lower bounds 
n animals = {dog,cat,fish,eagle,snake, …} 
yes/no questions 
INFORMATION THEORETIC LOWER BOUND: 
k³ log2 n
Lower bounds for sorting 
sorting by comparisons 
yes/no questions: is A[i]>A[j] ? 
data are not used to “control” 
computation in any other way 
A[1..n] 
1 2 3 
1 3 2 
2 1 3 
• 3 1 
3 1 2 
3 2 1
Lower bounds for sorting 
sorting by comparisons 
yes/no questions: is A[i]>A[j] ? 
A[1..n] 
log a*b = log a + log b 
k ³ log2 n! ³ 
log2 n + log2 (n-1) + … log2 1 ³ 
(n/2) log2 (n/2) = Q(n log n)
Lower bounds for sorting 
Theorem: 
Any comparison based sorting algorithm 
requires W(n ln n) comparisons in the 
worst-case.
Lower bounds for search in sorted array 
INPUT: array A[1..n], element x 
OUTPUT: a position of x in A if x is in A 
^ otherwise
Lower bounds for search in sorted array 
INPUT: array A[1..n], element x 
OUTPUT: a position of x in A if x is in A 
^ otherwise 
Theorem: 
Any comparison based algorithm for 
searching an element in a sorted array 
requires W(ln n) comparisons in the 
worst-case.
Lower bounds for minimum 
INPUT: array A[1..n] 
OUTPUT: the smallest element of A
Lower bounds for minimum 
INPUT: array A[1..n] 
OUTPUT: the smallest element of A 
INFORMATION THEORETIC LOWER BOUND: 
at least W(ln n) comparisons 
ADVERSARY LOWER BOUND: 
at least W(n) comparisons
Counting sort 
array A[1..n] containing numbers from {1,…,k} 
1st pass: 
count how many times iÎ {1,…,k} occurs 
2nd pass: 
put the elements in B
Counting sort 
array A[1..n] containing numbers from {1,…,k} 
for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=0 
for I ¬ 1 to k+1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
D[A[j]]++ 
B[ D[A[j]] ] ¬ A[j]
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 1 5 12 15
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 2 5 12 15 
1
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 2 6 12 15 
1 2
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 2 6 13 15 
1 2 3
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 2 7 13 15 
1 2 2 3
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 
C 4 7 3 2 
D 5 12 15 17 
1 1 1 1 2 2 2 2 2 2 2 3 3 3 4 4
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
stable sort = after sorting the items with the 
same key don’t switch order 
running time = O(n+k)
Counting sort for i ¬ 1 to k do C[i] ¬ 0 
for j ¬ 1 to n do C[A[j]]++ 
D[1]=1 
for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] 
for j ¬ 1 to n do 
B[ D[A[j]] ] ¬ A[j] 
D[A[j]]++ 
stable sort = after sorting the items with the 
same key don’t switch order 
running time = O(n+k) 
What if e.g., k = n2 ?
Radix sort 
array A[1..n] containing numbers from {0,…,k2 - 1} 
1) sort using counting sort with 
key = x mod k 
2) sort using counting sort with 
key = ë x/k û 
Running time = ?
Radix sort 
array A[1..n] containing numbers from {0,…,k2 - 1} 
1) sort using counting sort with 
key = x mod k 
2) sort using counting sort with 
key = ë x/k û 
Running time = O(n + k)
Radix sort 
array A[1..n] containing numbers from {0,…,k2 - 1} 
example k=10 
28 
70 
21 
20 
42 
21 
43 
42 
23 
32 
32 
43 
70 
23 
18 
28 
29 
18 
20 
29
Radix sort 
array A[1..n] containing numbers from {0,…,k2 - 1} 
example k=10 
28 
70 
21 
20 
42 
21 
43 
42 
23 
32 
32 
43 
70 
23 
18 
28 
29 
18 
20 
29
Radix sort 
array A[1..n] containing numbers from {0,…,k2 - 1} 
example k=10 
28 
70 
21 
20 
42 
21 
43 
42 
23 
32 
32 
43 
70 
23 
18 
28 
29 
18 
20 
29 
18 
20 
21 
23 
28 
29 
32 
42 
43 
70
Radix sort 
array A[1..n] containing numbers from {0,…,kd - 1} 
1) sort using counting sort with 
key = x mod k 
2) sort using counting sort with 
key = ë x/k û mod k 
3) sort using counting sort with 
key = ë x/k2 û mod k 
… 
d) sort using counting sort with 
key = ë x/kd-1 û mod k
Radix sort 
array A[1..n] containing numbers from {0,…,kd - 1} 
Correctness: after s-th step the numbers 
are sorted according to x mod ks 
Proof: By induction. Base case s=1 is trivial. 
1) sort using counting sort with 
key = x mod k
Radix sort 
array A[1..n] containing numbers from {0,…,kd - 1} 
Correctness: after s-th step the numbers 
are sorted according to x mod ks 
Proof: Now assume IH and execute s+1st step. Let x,y 
be such that x mod ks+1 < y mod ks+1. Then either 
ë x/ks û mod k < ë y/ks û mod k or 
ë x/ks û mod k = ë y/ks û mod k and x mod ks < y mod ks
Bucket sort 
linear time sorting algorithm on average 
Assume some distribution on input. 
INPUT: n independently random numbers from the 
uniform distribution on the interval [0,1].
Bucket sort 
INPUT: n independently random numbers from the 
uniform distribution on the interval [0,1]. 
for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1]
Bucket sort 
INPUT: n independently random numbers from the 
uniform distribution on the interval [0,1]. 
0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.82, 0.14, 0.19 
for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1]
Bucket sort 
INPUT: n independently random numbers from the 
uniform distribution on the interval [0,1]. 
0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.52, 0.14, 0.19 
1 2 5 7 1 3 1 5 1 1 
B[1]: 0.13, 0.18, 0.12, 0.14, 0.19 
B[2]: 0.23 
B[3]: 0.34 
B[5]: 0.56, 0.52 
B[7]: 0.74 
for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1]
Bucket sort 
INPUT: n independently random numbers from the 
uniform distribution on the interval [0,1]. 
0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.52, 0.14, 0.19 
1 2 5 7 1 3 1 5 1 1 
B[1]: 0.12, 0.13, 0.14, 0.18, 0.19 
B[2]: 0.23 
B[3]: 0.34 
B[5]: 0.52, 0.56 
B[7]: 0.74 
for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1]
Bucket sort for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1] 
assume we use insert-sort 
worst-case running time?
Bucket sort for i ¬ 1 to n do 
insert A[i] into list B[ ëA[i]*nû ] 
for i ¬ 0 to n-1 do 
sort list B[i] 
output lists B[0],…,B[n-1] 
assume we use insert-sort 
average-case running time? 
X0, X1, … , Xn-1 where Xi is the number of 
items that fall inside the i-th bucket
Bucket sort 
X0, X1, … , Xn-1 where Xi is the number of 
items that fall inside the i-th bucket 
X0 
2 + X1 
2 + … + Xn-1 
2 
What is E[X0 
2 + X1 
2 + … + Xn-1 
2] ? 
E[X0 
2 + … + Xn-1 
2 ] = 
E[X0 
2] + … + E[Xn-1 
2 ] = 
n E[X0 
2] 
linearity of expectation 
symmetry of the problem
Bucket sort 
E[X0 
2] What is E[X0] ? 
value of X0 
0 (1-p)n 
1 n (1-p) n-1 
k binomial(n,k) pk (1-p)n-k 
n pn 
p=1/n
Bucket sort 
E[X0 
2] E[X0] = 1 
0 (1-p)n 
1 n (1-p) n-1 
k binomial(n,k) pk (1-p)n-k 
n pn 
p=1/n 
n 
E[X0] = å k * binomial(n,k) pk (1-p)n-k 
k=0
Bucket sort 
E[X0 
2] E[X0] = 1 
p=1/n 
n 
E[X0] = å k * binomial(n,k) pk (1-p)n-k 
k=1 
binomial (n,k) = (n/k) * binomial (n-1,k-1) 
n 
   å binomial(n,k) pk (1-p)n-k = 1 
k=0
Bucket sort 
E[X0 
2] E[X0] = 1 
p=1/n 
n 
E[X0] = å n* binomial(n-1,k-1) pk (1-p)n-k 
k=1 
n 
n 
= n*p å binomial(n-1,k-1) pk-1(1-p)n-k 
= n*p 
k=1 
   å binomial(n,k) pk (1-p)n-k = 1 
k=0
Bucket sort 
E[X0 
2] 
0 (1-p)n 
1 n (1-p) n-1 
k binomial(n,k) pk (1-p)n-k 
n pn 
p=1/n 
2]= å k2 * binomial(n,k) pk (1-p)n-k 
k=0 
E[X0 
n
Bucket sort 
E[X0 
2] 
p=1/n 
E[X0 
n 
2]= å k2 * binomial(n,k) pk (1-p)n-k 
k=0 
n 
= å k * binomial(n,k) pk (1-p)n-k 
k=0 
+ 
n 
å k(k-1) * binomial(n,k) pk (1-p)n-k 
k=0
Bucket sort 
E[X0 
2] 
p=1/n 
E[X0 
n 
2]= å k2 * binomial(n,k) pk (1-p)n-k 
k=0 
n 
= å k * binomial(n,k) pk (1-p)n-k 
k=0 
+ 
n 
n*p 
å k(k-1) * binomial(n,k) pk (1-p)n-k 
k=0
Bucket sort 
E[X0 
2] 
p=1/n 
n 
2]= å k(k-1) * binomial(n,k) pk (1-p)n-k 
E[X0 
+n*p 
k=2 
binomial (n,k) = (n/k) * binomial (n-1,k-1) = 
(n/k) * ((n-1)/(k-1)) * binomial (n-2,k-2) 
E[X0 
2] = n* (n-1) * p2 + n*p

Más contenido relacionado

La actualidad más candente

47 operations of 2nd degree expressions and formulas
47 operations of 2nd degree expressions and formulas47 operations of 2nd degree expressions and formulas
47 operations of 2nd degree expressions and formulasalg1testreview
 
Chapter 5 indices & logarithms
Chapter 5  indices & logarithmsChapter 5  indices & logarithms
Chapter 5 indices & logarithmsatiqah ayie
 
1.5 notation and algebra of functions
1.5 notation and algebra of functions1.5 notation and algebra of functions
1.5 notation and algebra of functionsmath123c
 
Transforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard FormTransforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard FormIvy Estrella
 
5 algebra of functions
5 algebra of functions5 algebra of functions
5 algebra of functionsTzenma
 
02[anal add math cd]
02[anal add math cd]02[anal add math cd]
02[anal add math cd]ilya shafiqah
 
1.0 factoring trinomials the ac method and making lists-x
1.0 factoring trinomials  the ac method and making lists-x1.0 factoring trinomials  the ac method and making lists-x
1.0 factoring trinomials the ac method and making lists-xmath260
 
Ejercicios prueba de algebra de la UTN- widmar aguilar
Ejercicios prueba de algebra de la UTN-  widmar aguilarEjercicios prueba de algebra de la UTN-  widmar aguilar
Ejercicios prueba de algebra de la UTN- widmar aguilarWidmar Aguilar Gonzalez
 
2 complex numbers part 2 of 3
2 complex numbers part 2 of 32 complex numbers part 2 of 3
2 complex numbers part 2 of 3naveenkumar9211
 
cbse class 12 math question paper
cbse class 12 math question papercbse class 12 math question paper
cbse class 12 math question paperPady Srini
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions xmath260
 
Assessments for class xi
Assessments  for class  xi Assessments  for class  xi
Assessments for class xi indu psthakur
 
Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)Fatini Adnan
 
1.2 algebraic expressions t
1.2 algebraic expressions t1.2 algebraic expressions t
1.2 algebraic expressions tmath260
 

La actualidad más candente (20)

47 operations of 2nd degree expressions and formulas
47 operations of 2nd degree expressions and formulas47 operations of 2nd degree expressions and formulas
47 operations of 2nd degree expressions and formulas
 
Chapter 5 indices & logarithms
Chapter 5  indices & logarithmsChapter 5  indices & logarithms
Chapter 5 indices & logarithms
 
Complex numbers
Complex numbersComplex numbers
Complex numbers
 
1.5 notation and algebra of functions
1.5 notation and algebra of functions1.5 notation and algebra of functions
1.5 notation and algebra of functions
 
Transforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard FormTransforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard Form
 
Set 1 mawar
Set 1 mawarSet 1 mawar
Set 1 mawar
 
5 algebra of functions
5 algebra of functions5 algebra of functions
5 algebra of functions
 
Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1
 
02[anal add math cd]
02[anal add math cd]02[anal add math cd]
02[anal add math cd]
 
1.0 factoring trinomials the ac method and making lists-x
1.0 factoring trinomials  the ac method and making lists-x1.0 factoring trinomials  the ac method and making lists-x
1.0 factoring trinomials the ac method and making lists-x
 
Ejercicios prueba de algebra de la UTN- widmar aguilar
Ejercicios prueba de algebra de la UTN-  widmar aguilarEjercicios prueba de algebra de la UTN-  widmar aguilar
Ejercicios prueba de algebra de la UTN- widmar aguilar
 
2 complex numbers part 2 of 3
2 complex numbers part 2 of 32 complex numbers part 2 of 3
2 complex numbers part 2 of 3
 
Functions & graphs
Functions & graphsFunctions & graphs
Functions & graphs
 
cbse class 12 math question paper
cbse class 12 math question papercbse class 12 math question paper
cbse class 12 math question paper
 
Matematica
MatematicaMatematica
Matematica
 
Algebra formulas
Algebra formulas Algebra formulas
Algebra formulas
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions x
 
Assessments for class xi
Assessments  for class  xi Assessments  for class  xi
Assessments for class xi
 
Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)
 
1.2 algebraic expressions t
1.2 algebraic expressions t1.2 algebraic expressions t
1.2 algebraic expressions t
 

Destacado

SAP TOP TEN ENTERPRISE MOBILITY 2013
SAP TOP TEN ENTERPRISE MOBILITY 2013SAP TOP TEN ENTERPRISE MOBILITY 2013
SAP TOP TEN ENTERPRISE MOBILITY 2013Riccardo Bellesia
 
Theories of the universe 2
Theories of the universe 2Theories of the universe 2
Theories of the universe 2geislau15
 
Trading spaces
Trading spacesTrading spaces
Trading spacesiamslempy
 
FUNNY "WANTED" POSTERS
FUNNY "WANTED" POSTERSFUNNY "WANTED" POSTERS
FUNNY "WANTED" POSTERSviv_h
 
Răspunsul Aeroportului Internațional Cluj vizavi de parcare
Răspunsul Aeroportului Internațional Cluj vizavi de parcareRăspunsul Aeroportului Internațional Cluj vizavi de parcare
Răspunsul Aeroportului Internațional Cluj vizavi de parcareRobin Molnar
 

Destacado (6)

SAP TOP TEN ENTERPRISE MOBILITY 2013
SAP TOP TEN ENTERPRISE MOBILITY 2013SAP TOP TEN ENTERPRISE MOBILITY 2013
SAP TOP TEN ENTERPRISE MOBILITY 2013
 
Theories of the universe 2
Theories of the universe 2Theories of the universe 2
Theories of the universe 2
 
Trading spaces
Trading spacesTrading spaces
Trading spaces
 
FUNNY "WANTED" POSTERS
FUNNY "WANTED" POSTERSFUNNY "WANTED" POSTERS
FUNNY "WANTED" POSTERS
 
R and Access 2007
R and Access 2007R and Access 2007
R and Access 2007
 
Răspunsul Aeroportului Internațional Cluj vizavi de parcare
Răspunsul Aeroportului Internațional Cluj vizavi de parcareRăspunsul Aeroportului Internațional Cluj vizavi de parcare
Răspunsul Aeroportului Internațional Cluj vizavi de parcare
 

Similar a Top school in delhi ncr

Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Hossain Md Shakhawat
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfShiwani Gupta
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonshin
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sortUmmar Hayat
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.pptjvjfvvoa
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDeepakGowda357858
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and AnalysisReetesh Gupta
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functionsallyn joy calcaben
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortShanmuganathan C
 
All homework and exams in one file.pdf
All homework and exams in one file.pdfAll homework and exams in one file.pdf
All homework and exams in one file.pdfAnn Wera
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptxpallavidhade2
 
Insert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C ProgrammingInsert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C Programmingchandankumar364348
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probabilitybryan111472
 

Similar a Top school in delhi ncr (20)

Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse students
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and Analysis
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Linear Sorting
Linear SortingLinear Sorting
Linear Sorting
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sort
 
All homework and exams in one file.pdf
All homework and exams in one file.pdfAll homework and exams in one file.pdf
All homework and exams in one file.pdf
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
Computer science-formulas
Computer science-formulasComputer science-formulas
Computer science-formulas
 
Insert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C ProgrammingInsert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C Programming
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 

Más de Edhole.com

Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarkaEdhole.com
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarkaEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarkaEdhole.com
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarkaEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbaiEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 

Más de Edhole.com (20)

Ca in patna
Ca in patnaCa in patna
Ca in patna
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarka
 
Ca in dwarka
Ca in dwarkaCa in dwarka
Ca in dwarka
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarka
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Ca in patna
Ca in patnaCa in patna
Ca in patna
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarka
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarka
 
Ca in dwarka
Ca in dwarkaCa in dwarka
Ca in dwarka
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbai
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 

Último

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

Top school in delhi ncr

  • 1. “Monte Carlo method” generate M random permutations of {1,…,20} let H be the number of those in which exactly one person gets his/her card back output H/M
  • 2. Lower bounds number from {1,2,3,…,9} 3 yes/no questions Can you always figure out the number?
  • 3. Lower bounds number from {1,2,3,…,8} 3 yes/no questions Can you always figure out the number?
  • 4. Lower bounds number from {1,2,3,…,8} 3 yes/no questions in {1,2,3,4} ? Y N in {1,2} ? in {5,6} ? Y Y N N =1 ? =3 ? =5 ? =7 ? Y Y Y Y N N N N 1 2 3 4 5 6 7 8
  • 5. Lower bounds number from {1,2,3,…,n} k yes/no questions
  • 6. Lower bounds number from {1,2,3,…,n} k yes/no questions k = é log2 n ù
  • 7. Lower bounds number from {1,2,3,…,n} k yes/no questions k = é log2 n ù INFORMATION THEORETIC LOWER BOUND: k³ log2 n
  • 8. Lower bounds n animals = {dog,cat,fish,eagle,snake, …} yes/no questions INFORMATION THEORETIC LOWER BOUND: k³ log2 n
  • 9. Lower bounds for sorting sorting by comparisons yes/no questions: is A[i]>A[j] ? data are not used to “control” computation in any other way A[1..n] 1 2 3 1 3 2 2 1 3 • 3 1 3 1 2 3 2 1
  • 10. Lower bounds for sorting sorting by comparisons yes/no questions: is A[i]>A[j] ? A[1..n] log a*b = log a + log b k ³ log2 n! ³ log2 n + log2 (n-1) + … log2 1 ³ (n/2) log2 (n/2) = Q(n log n)
  • 11. Lower bounds for sorting Theorem: Any comparison based sorting algorithm requires W(n ln n) comparisons in the worst-case.
  • 12. Lower bounds for search in sorted array INPUT: array A[1..n], element x OUTPUT: a position of x in A if x is in A ^ otherwise
  • 13. Lower bounds for search in sorted array INPUT: array A[1..n], element x OUTPUT: a position of x in A if x is in A ^ otherwise Theorem: Any comparison based algorithm for searching an element in a sorted array requires W(ln n) comparisons in the worst-case.
  • 14. Lower bounds for minimum INPUT: array A[1..n] OUTPUT: the smallest element of A
  • 15. Lower bounds for minimum INPUT: array A[1..n] OUTPUT: the smallest element of A INFORMATION THEORETIC LOWER BOUND: at least W(ln n) comparisons ADVERSARY LOWER BOUND: at least W(n) comparisons
  • 16. Counting sort array A[1..n] containing numbers from {1,…,k} 1st pass: count how many times iÎ {1,…,k} occurs 2nd pass: put the elements in B
  • 17. Counting sort array A[1..n] containing numbers from {1,…,k} for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=0 for I ¬ 1 to k+1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do D[A[j]]++ B[ D[A[j]] ] ¬ A[j]
  • 18. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 1 5 12 15
  • 19. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 2 5 12 15 1
  • 20. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 2 6 12 15 1 2
  • 21. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 2 6 13 15 1 2 3
  • 22. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 2 7 13 15 1 2 2 3
  • 23. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ 1 2 3 2 2 4 2 1 1 2 3 3 2 1 2 4 C 4 7 3 2 D 5 12 15 17 1 1 1 1 2 2 2 2 2 2 2 3 3 3 4 4
  • 24. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ stable sort = after sorting the items with the same key don’t switch order running time = O(n+k)
  • 25. Counting sort for i ¬ 1 to k do C[i] ¬ 0 for j ¬ 1 to n do C[A[j]]++ D[1]=1 for I ¬ 1 to k-1 do D[i+1] ¬ D[i]+C[i] for j ¬ 1 to n do B[ D[A[j]] ] ¬ A[j] D[A[j]]++ stable sort = after sorting the items with the same key don’t switch order running time = O(n+k) What if e.g., k = n2 ?
  • 26. Radix sort array A[1..n] containing numbers from {0,…,k2 - 1} 1) sort using counting sort with key = x mod k 2) sort using counting sort with key = ë x/k û Running time = ?
  • 27. Radix sort array A[1..n] containing numbers from {0,…,k2 - 1} 1) sort using counting sort with key = x mod k 2) sort using counting sort with key = ë x/k û Running time = O(n + k)
  • 28. Radix sort array A[1..n] containing numbers from {0,…,k2 - 1} example k=10 28 70 21 20 42 21 43 42 23 32 32 43 70 23 18 28 29 18 20 29
  • 29. Radix sort array A[1..n] containing numbers from {0,…,k2 - 1} example k=10 28 70 21 20 42 21 43 42 23 32 32 43 70 23 18 28 29 18 20 29
  • 30. Radix sort array A[1..n] containing numbers from {0,…,k2 - 1} example k=10 28 70 21 20 42 21 43 42 23 32 32 43 70 23 18 28 29 18 20 29 18 20 21 23 28 29 32 42 43 70
  • 31. Radix sort array A[1..n] containing numbers from {0,…,kd - 1} 1) sort using counting sort with key = x mod k 2) sort using counting sort with key = ë x/k û mod k 3) sort using counting sort with key = ë x/k2 û mod k … d) sort using counting sort with key = ë x/kd-1 û mod k
  • 32. Radix sort array A[1..n] containing numbers from {0,…,kd - 1} Correctness: after s-th step the numbers are sorted according to x mod ks Proof: By induction. Base case s=1 is trivial. 1) sort using counting sort with key = x mod k
  • 33. Radix sort array A[1..n] containing numbers from {0,…,kd - 1} Correctness: after s-th step the numbers are sorted according to x mod ks Proof: Now assume IH and execute s+1st step. Let x,y be such that x mod ks+1 < y mod ks+1. Then either ë x/ks û mod k < ë y/ks û mod k or ë x/ks û mod k = ë y/ks û mod k and x mod ks < y mod ks
  • 34. Bucket sort linear time sorting algorithm on average Assume some distribution on input. INPUT: n independently random numbers from the uniform distribution on the interval [0,1].
  • 35. Bucket sort INPUT: n independently random numbers from the uniform distribution on the interval [0,1]. for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1]
  • 36. Bucket sort INPUT: n independently random numbers from the uniform distribution on the interval [0,1]. 0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.82, 0.14, 0.19 for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1]
  • 37. Bucket sort INPUT: n independently random numbers from the uniform distribution on the interval [0,1]. 0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.52, 0.14, 0.19 1 2 5 7 1 3 1 5 1 1 B[1]: 0.13, 0.18, 0.12, 0.14, 0.19 B[2]: 0.23 B[3]: 0.34 B[5]: 0.56, 0.52 B[7]: 0.74 for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1]
  • 38. Bucket sort INPUT: n independently random numbers from the uniform distribution on the interval [0,1]. 0.13, 0.23, 0.56, 0.74, 0.18, 0.34, 0.12, 0.52, 0.14, 0.19 1 2 5 7 1 3 1 5 1 1 B[1]: 0.12, 0.13, 0.14, 0.18, 0.19 B[2]: 0.23 B[3]: 0.34 B[5]: 0.52, 0.56 B[7]: 0.74 for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1]
  • 39. Bucket sort for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1] assume we use insert-sort worst-case running time?
  • 40. Bucket sort for i ¬ 1 to n do insert A[i] into list B[ ëA[i]*nû ] for i ¬ 0 to n-1 do sort list B[i] output lists B[0],…,B[n-1] assume we use insert-sort average-case running time? X0, X1, … , Xn-1 where Xi is the number of items that fall inside the i-th bucket
  • 41. Bucket sort X0, X1, … , Xn-1 where Xi is the number of items that fall inside the i-th bucket X0 2 + X1 2 + … + Xn-1 2 What is E[X0 2 + X1 2 + … + Xn-1 2] ? E[X0 2 + … + Xn-1 2 ] = E[X0 2] + … + E[Xn-1 2 ] = n E[X0 2] linearity of expectation symmetry of the problem
  • 42. Bucket sort E[X0 2] What is E[X0] ? value of X0 0 (1-p)n 1 n (1-p) n-1 k binomial(n,k) pk (1-p)n-k n pn p=1/n
  • 43. Bucket sort E[X0 2] E[X0] = 1 0 (1-p)n 1 n (1-p) n-1 k binomial(n,k) pk (1-p)n-k n pn p=1/n n E[X0] = å k * binomial(n,k) pk (1-p)n-k k=0
  • 44. Bucket sort E[X0 2] E[X0] = 1 p=1/n n E[X0] = å k * binomial(n,k) pk (1-p)n-k k=1 binomial (n,k) = (n/k) * binomial (n-1,k-1) n å binomial(n,k) pk (1-p)n-k = 1 k=0
  • 45. Bucket sort E[X0 2] E[X0] = 1 p=1/n n E[X0] = å n* binomial(n-1,k-1) pk (1-p)n-k k=1 n n = n*p å binomial(n-1,k-1) pk-1(1-p)n-k = n*p k=1 å binomial(n,k) pk (1-p)n-k = 1 k=0
  • 46. Bucket sort E[X0 2] 0 (1-p)n 1 n (1-p) n-1 k binomial(n,k) pk (1-p)n-k n pn p=1/n 2]= å k2 * binomial(n,k) pk (1-p)n-k k=0 E[X0 n
  • 47. Bucket sort E[X0 2] p=1/n E[X0 n 2]= å k2 * binomial(n,k) pk (1-p)n-k k=0 n = å k * binomial(n,k) pk (1-p)n-k k=0 + n å k(k-1) * binomial(n,k) pk (1-p)n-k k=0
  • 48. Bucket sort E[X0 2] p=1/n E[X0 n 2]= å k2 * binomial(n,k) pk (1-p)n-k k=0 n = å k * binomial(n,k) pk (1-p)n-k k=0 + n n*p å k(k-1) * binomial(n,k) pk (1-p)n-k k=0
  • 49. Bucket sort E[X0 2] p=1/n n 2]= å k(k-1) * binomial(n,k) pk (1-p)n-k E[X0 +n*p k=2 binomial (n,k) = (n/k) * binomial (n-1,k-1) = (n/k) * ((n-1)/(k-1)) * binomial (n-2,k-2) E[X0 2] = n* (n-1) * p2 + n*p