8
Most read
9
Most read
17
Most read
Analysis of Algorithms
Probabilistic Analysis
Andres Mendez-Vazquez
March 16, 2015
1 / 19
Outline
1 The Hiring Problem
2 The Hiring Algorithm
3 Paradigm
4 Indicator Random Variable
5 The Randomized Hiring
6 Methods to Enforce Randomization
Permute By Sorting
Permute in Place
2 / 19
A Random Process
First
In order to exemplify the usage of the probabilistic analysis, we will use the
Hiring Problem.
Why?
It is clear that hiring a person is a random process.
An Example
Many possible process involving a Expected count in the number of steps
of them.
3 / 19
The Hiring Problem
Suppose the following
You are using an employment agency to hire a new oce assistant.
You interview the candidate and must immediately decide whether or
not to hire that person.
Cost
Cost to interview is ci per candidate.
Cost to hire is ch per candidate.
Assume that ch  ci .
Observation!
You must have somebody working all the time!
You will always hire the best candidate that you interview!
4 / 19
Hiring Algorithm
Hire-Assistant(n)
b e s t = 0 // c a n d i d a t e dummy
f o r i = 1 t o n
i n t e r v i e w i
i f c a n d i d a t e i i s b e t t e r t h a n c a n d i d a t e b e s t
t h e n b e s t = i
h i r e c a n d i d a t e i
COST Given n candidates and we hire m of them, O(nci + mch)
5 / 19
Paradigm
We have that
We need to nd the maximum or minimum in a sequence by
examining each element and maintaining a current WINNER
The variable m denotes how many times we change our notion of
which element is currently winning.
Worst Case Analysis
You hire all of n
O(nci + nch) = O(nch)
Why? Because every time we hire somebody, we re somebody.
6 / 19
We want to avoid the worst case
How?
Because many times we do not get the worst case
Actually
Many times we get the Average input
This makes
The probability analysis a useful tool to analyze average complexities for
many algorithms
7 / 19
Probabilistic Analysis
Uniform Distribution Assumption
1 Assign a rank to each candidate i, rank : U → {1, 2, ..., n}
2 The possible number of permutations of individuals by the rank is n!
3 Therefore, if we assume that all individuals have the same probability
to have any ranking - Unifrom Distribution Assumption.
4 The input in the hiring problem comes from a uniform distribution.
Essentials of Probability Analysis
You assume a distribution over permutation of elements.
The expectation is over this distribution.
This technique requires that we can make a reasonable
characterization of the input distribution.
8 / 19
Indicator Random Variable
Indicator Random Variable
We require to use the indicator random variable to facilitate the use of
probabilistic analysis:
I {A} =
0 if A does not ocurr
1 if A does ocurr
.
Using this we have
Lemma 5.1
Given a sample space S and an event A in the sample space S, let
XA = I {A}. Then E [XA] = Pr {A}.
9 / 19
Analyzing Hiring By Indicator Variable
Given X
Assume a X, the random variable of the number of times we hire a
person. Then E [X] = n
x=1 xPr {X = x}
We could analyze the hiring problem by using the indicator function:
Xi = I { candidate i is hired} =
1 if candidate i is hired
0 if candidate i is not hired
.
In addition
X = X1 + X2 + ... + Xn
An because the candidates come randomly (Uniform Assumption), we
have that E [Xi ] = Pr { cantidate i is hired} = 1
i
After all each time, we get a new i candidate is better than the
previous 1 to i − 1.
10 / 19
Analyzing Hiring By Indicator Variable
Finally...
We can calculate
E [X] = E
n
i=1
Xi =
n
i=1
E [X] =
n
i=1
1
i
= ln n + O (1) .
Final hiring cost is O (ch ln n).
11 / 19
Hiring Problem
What if
The employment agency sends us a list of all n candidates in advance.
On each day, we randomly choose a candidate from the list to
interview.
Instead of relaying on the candidate being presented to us in a random
order, we take control of the process and enforce a random order.
What makes an algorithm randomized?
An algorithm is randomized if its behavior is determined in part by
values produced by a random-number generator.
A random-number generator is implemented by a
pseudorandom-number generator, which is a deterministic method
returning numbers that look random and can pass certain statistical
tests.
12 / 19
Hiring Algorithm
Randomized-Hire-Assistant(n)
Randomly Permute t h e l i s t o f c a n d i d a t e s
b e s t = 0 // c a n d i d a t e dummy
f o r i = 1 t o n
i n t e r v i e w i
i f c a n d i d a t e i i s b e t t e r t h a n c a n d i d a t e b e s t
t h e n b e s t = i
h i r e c a n d i d a t e i
Lemma (5.3)
The expected hiring cost of the procedure Randomized-Hiring-Assistant is
O(ch ln n)
Proof.
Go to the Blackboard.
13 / 19
Methods to Enforce Randomization
Randomly Permute Arrays
1 A = 1, 2, 3, 4
2 P = 36, 3, 97, 19
Then, sort B = 2, 4, 1, 3
Permute-By-Sorting(A)
n = l e n g h t [ A ]
f o r i = 1 t o n
do P [ i ]=RANDOM( 1 , n ^3)
s o r t A , u s i n g P a s s o r t k e y s
r e t u r n A
15 / 19
Proving Correctness of Permute-By-Sorting
Lemma 5.4
Procedure Permute-By-Sorting produces a uniform random permutation of
the input, assuming that all priorities are distinct.
Proof: Go to the Blackboard
16 / 19
Permute in Place
Randomize-In-Place(A)
n = l e n g h t [ A ]
f o r i = 1 t o n
do swap A [ i ] − A [RANDOM( i , n ) ]
Lemma (5.5)
Procedure Randomize-In-Place computes a unifrom random permutation.
Proof.
Go to the Blackboard.
18 / 19
Exercises
5.1-1
5.1-2
5.2-1
5.2-3
5.2-5
5.3-1
5.3-3
5.3-4
19 / 19

More Related Content

PPTX
Theory of Computation
PPTX
Decision properties of reular languages
PPT
Turing Machine
PPTX
Asymptotic Notation
PPTX
daa-unit-3-greedy method
PPTX
Knapsack problem using greedy approach
PDF
Daa notes 1
PPT
01 knapsack using backtracking
Theory of Computation
Decision properties of reular languages
Turing Machine
Asymptotic Notation
daa-unit-3-greedy method
Knapsack problem using greedy approach
Daa notes 1
01 knapsack using backtracking

What's hot (20)

PPT
Np cooks theorem
PPT
Randomized algorithms ver 1.0
PPTX
Asymptotic Notations
PPT
Divide and conquer
PPTX
Lexical analysis - Compiler Design
PPTX
Modern Block Cipher- Modern Symmetric-Key Cipher
PDF
Asymptotic notation
PPTX
Critical section problem in operating system.
PPT
Dinive conquer algorithm
PDF
Recurrence relation solutions
PPT
Recursion tree method
PPT
Data Structures- Part5 recursion
PPTX
Difference Program vs Process vs Thread
PPTX
Undecidability.pptx
PPTX
Backtracking
PDF
Code optimization in compiler design
PDF
NFA to DFA
PPTX
Graph coloring using backtracking
PPTX
Strassen's matrix multiplication
Np cooks theorem
Randomized algorithms ver 1.0
Asymptotic Notations
Divide and conquer
Lexical analysis - Compiler Design
Modern Block Cipher- Modern Symmetric-Key Cipher
Asymptotic notation
Critical section problem in operating system.
Dinive conquer algorithm
Recurrence relation solutions
Recursion tree method
Data Structures- Part5 recursion
Difference Program vs Process vs Thread
Undecidability.pptx
Backtracking
Code optimization in compiler design
NFA to DFA
Graph coloring using backtracking
Strassen's matrix multiplication
Ad

Viewers also liked (17)

PPTX
Bubble sort
PPTX
Randomized Algorithm
PPT
Randomized Algorithms
PPTX
Topic 1.4: Randomized Algorithms
RTF
Amortized complexity
PDF
The Hiring Problem
PDF
13 Amortized Analysis
PPTX
9 big o-notation
PPTX
Big o notation
PPTX
Algorithm big o
PPTX
Asymptotic notations
PPT
Asymptotic notations
PPTX
Asymptotic Notation and Data Structures
PPTX
Divide and Conquer - Part 1
PPTX
Algorithm and pseudo codes
PDF
Writing algorithms
PPTX
Introduction to Pseudocode
Bubble sort
Randomized Algorithm
Randomized Algorithms
Topic 1.4: Randomized Algorithms
Amortized complexity
The Hiring Problem
13 Amortized Analysis
9 big o-notation
Big o notation
Algorithm big o
Asymptotic notations
Asymptotic notations
Asymptotic Notation and Data Structures
Divide and Conquer - Part 1
Algorithm and pseudo codes
Writing algorithms
Introduction to Pseudocode
Ad

Similar to 03 Analysis of Algorithms: Probabilistic Analysis (20)

PPTX
Indicator Random Variables
PPTX
AA_Unit_2.pptx
PPTX
daa unit 1.pptx
PDF
Chapter-1-Introduction-to-Aglorithms.pdf
PPTX
Algorithm in data structure bca .pptx
PDF
Computer Applications in Business
PDF
Anlysis and design of algorithms part 1
PPTX
Ch 2Algo Analysis.pptxCh 2Algo Analysis.pptx
PDF
Chapter IV Algorithm for I3ab Ams at itc
PPT
Design and analysis of algorithm in Computer Science
PDF
sem-UCT-hiring.pdf
PPTX
Unit 1.pptx
PPT
Analysis.ppt
PPTX
PPT-Chap-1205-Algorithmsawtghrjkmjtr.pptx
PPTX
Algorithm.pptx
PPTX
Algorithm.pptx
PDF
Runtime Analysis of Population-based Evolutionary Algorithms
PDF
Runtime Analysis of Population-based Evolutionary Algorithms
PDF
3108 3389-1-pb
Indicator Random Variables
AA_Unit_2.pptx
daa unit 1.pptx
Chapter-1-Introduction-to-Aglorithms.pdf
Algorithm in data structure bca .pptx
Computer Applications in Business
Anlysis and design of algorithms part 1
Ch 2Algo Analysis.pptxCh 2Algo Analysis.pptx
Chapter IV Algorithm for I3ab Ams at itc
Design and analysis of algorithm in Computer Science
sem-UCT-hiring.pdf
Unit 1.pptx
Analysis.ppt
PPT-Chap-1205-Algorithmsawtghrjkmjtr.pptx
Algorithm.pptx
Algorithm.pptx
Runtime Analysis of Population-based Evolutionary Algorithms
Runtime Analysis of Population-based Evolutionary Algorithms
3108 3389-1-pb

More from Andres Mendez-Vazquez (20)

PDF
2.03 bayesian estimation
PDF
05 linear transformations
PDF
01.04 orthonormal basis_eigen_vectors
PDF
01.03 squared matrices_and_other_issues
PDF
01.02 linear equations
PDF
01.01 vector spaces
PDF
06 recurrent neural_networks
PDF
05 backpropagation automatic_differentiation
PDF
Zetta global
PDF
01 Introduction to Neural Networks and Deep Learning
PDF
25 introduction reinforcement_learning
PDF
Neural Networks and Deep Learning Syllabus
PDF
Introduction to artificial_intelligence_syllabus
PDF
Ideas 09 22_2018
PDF
Ideas about a Bachelor in Machine Learning/Data Sciences
PDF
Analysis of Algorithms Syllabus
PDF
20 k-means, k-center, k-meoids and variations
PDF
18.1 combining models
PDF
17 vapnik chervonenkis dimension
PDF
A basic introduction to learning
2.03 bayesian estimation
05 linear transformations
01.04 orthonormal basis_eigen_vectors
01.03 squared matrices_and_other_issues
01.02 linear equations
01.01 vector spaces
06 recurrent neural_networks
05 backpropagation automatic_differentiation
Zetta global
01 Introduction to Neural Networks and Deep Learning
25 introduction reinforcement_learning
Neural Networks and Deep Learning Syllabus
Introduction to artificial_intelligence_syllabus
Ideas 09 22_2018
Ideas about a Bachelor in Machine Learning/Data Sciences
Analysis of Algorithms Syllabus
20 k-means, k-center, k-meoids and variations
18.1 combining models
17 vapnik chervonenkis dimension
A basic introduction to learning

Recently uploaded (20)

PPTX
Design ,Art Across Digital Realities and eXtended Reality
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PPTX
Agentic Artificial Intelligence (Agentic AI).pptx
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
PDF
Mechanics of materials week 2 rajeshwari
PPTX
MAD Unit - 3 User Interface and Data Management (Diploma IT)
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PPTX
Solar energy pdf of gitam songa hemant k
PDF
Project_Mgmt_Institute_-Marc Marc Marc .pdf
PDF
SEH5E Unveiled: Enhancements and Key Takeaways for Certification Success
PDF
Computer organization and architecuture Digital Notes....pdf
PPTX
Cisco Network Behaviour dibuywvdsvdtdstydsdsa
PPT
Programmable Logic Controller PLC and Industrial Automation
PPT
UNIT-I Machine Learning Essentials for 2nd years
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PPTX
Micro1New.ppt.pptx the main themes if micro
PDF
Lesson 3 .pdf
PDF
August -2025_Top10 Read_Articles_ijait.pdf
Design ,Art Across Digital Realities and eXtended Reality
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
Environmental studies, Moudle 3-Environmental Pollution.pptx
Agentic Artificial Intelligence (Agentic AI).pptx
Unit1 - AIML Chapter 1 concept and ethics
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
Mechanics of materials week 2 rajeshwari
MAD Unit - 3 User Interface and Data Management (Diploma IT)
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
Solar energy pdf of gitam songa hemant k
Project_Mgmt_Institute_-Marc Marc Marc .pdf
SEH5E Unveiled: Enhancements and Key Takeaways for Certification Success
Computer organization and architecuture Digital Notes....pdf
Cisco Network Behaviour dibuywvdsvdtdstydsdsa
Programmable Logic Controller PLC and Industrial Automation
UNIT-I Machine Learning Essentials for 2nd years
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
Micro1New.ppt.pptx the main themes if micro
Lesson 3 .pdf
August -2025_Top10 Read_Articles_ijait.pdf

03 Analysis of Algorithms: Probabilistic Analysis

  • 1. Analysis of Algorithms Probabilistic Analysis Andres Mendez-Vazquez March 16, 2015 1 / 19
  • 2. Outline 1 The Hiring Problem 2 The Hiring Algorithm 3 Paradigm 4 Indicator Random Variable 5 The Randomized Hiring 6 Methods to Enforce Randomization Permute By Sorting Permute in Place 2 / 19
  • 3. A Random Process First In order to exemplify the usage of the probabilistic analysis, we will use the Hiring Problem. Why? It is clear that hiring a person is a random process. An Example Many possible process involving a Expected count in the number of steps of them. 3 / 19
  • 4. The Hiring Problem Suppose the following You are using an employment agency to hire a new oce assistant. You interview the candidate and must immediately decide whether or not to hire that person. Cost Cost to interview is ci per candidate. Cost to hire is ch per candidate. Assume that ch ci . Observation! You must have somebody working all the time! You will always hire the best candidate that you interview! 4 / 19
  • 5. Hiring Algorithm Hire-Assistant(n) b e s t = 0 // c a n d i d a t e dummy f o r i = 1 t o n i n t e r v i e w i i f c a n d i d a t e i i s b e t t e r t h a n c a n d i d a t e b e s t t h e n b e s t = i h i r e c a n d i d a t e i COST Given n candidates and we hire m of them, O(nci + mch) 5 / 19
  • 6. Paradigm We have that We need to nd the maximum or minimum in a sequence by examining each element and maintaining a current WINNER The variable m denotes how many times we change our notion of which element is currently winning. Worst Case Analysis You hire all of n O(nci + nch) = O(nch) Why? Because every time we hire somebody, we re somebody. 6 / 19
  • 7. We want to avoid the worst case How? Because many times we do not get the worst case Actually Many times we get the Average input This makes The probability analysis a useful tool to analyze average complexities for many algorithms 7 / 19
  • 8. Probabilistic Analysis Uniform Distribution Assumption 1 Assign a rank to each candidate i, rank : U → {1, 2, ..., n} 2 The possible number of permutations of individuals by the rank is n! 3 Therefore, if we assume that all individuals have the same probability to have any ranking - Unifrom Distribution Assumption. 4 The input in the hiring problem comes from a uniform distribution. Essentials of Probability Analysis You assume a distribution over permutation of elements. The expectation is over this distribution. This technique requires that we can make a reasonable characterization of the input distribution. 8 / 19
  • 9. Indicator Random Variable Indicator Random Variable We require to use the indicator random variable to facilitate the use of probabilistic analysis: I {A} = 0 if A does not ocurr 1 if A does ocurr . Using this we have Lemma 5.1 Given a sample space S and an event A in the sample space S, let XA = I {A}. Then E [XA] = Pr {A}. 9 / 19
  • 10. Analyzing Hiring By Indicator Variable Given X Assume a X, the random variable of the number of times we hire a person. Then E [X] = n x=1 xPr {X = x} We could analyze the hiring problem by using the indicator function: Xi = I { candidate i is hired} = 1 if candidate i is hired 0 if candidate i is not hired . In addition X = X1 + X2 + ... + Xn An because the candidates come randomly (Uniform Assumption), we have that E [Xi ] = Pr { cantidate i is hired} = 1 i After all each time, we get a new i candidate is better than the previous 1 to i − 1. 10 / 19
  • 11. Analyzing Hiring By Indicator Variable Finally... We can calculate E [X] = E n i=1 Xi = n i=1 E [X] = n i=1 1 i = ln n + O (1) . Final hiring cost is O (ch ln n). 11 / 19
  • 12. Hiring Problem What if The employment agency sends us a list of all n candidates in advance. On each day, we randomly choose a candidate from the list to interview. Instead of relaying on the candidate being presented to us in a random order, we take control of the process and enforce a random order. What makes an algorithm randomized? An algorithm is randomized if its behavior is determined in part by values produced by a random-number generator. A random-number generator is implemented by a pseudorandom-number generator, which is a deterministic method returning numbers that look random and can pass certain statistical tests. 12 / 19
  • 13. Hiring Algorithm Randomized-Hire-Assistant(n) Randomly Permute t h e l i s t o f c a n d i d a t e s b e s t = 0 // c a n d i d a t e dummy f o r i = 1 t o n i n t e r v i e w i i f c a n d i d a t e i i s b e t t e r t h a n c a n d i d a t e b e s t t h e n b e s t = i h i r e c a n d i d a t e i Lemma (5.3) The expected hiring cost of the procedure Randomized-Hiring-Assistant is O(ch ln n) Proof. Go to the Blackboard. 13 / 19
  • 14. Methods to Enforce Randomization Randomly Permute Arrays 1 A = 1, 2, 3, 4 2 P = 36, 3, 97, 19 Then, sort B = 2, 4, 1, 3 Permute-By-Sorting(A) n = l e n g h t [ A ] f o r i = 1 t o n do P [ i ]=RANDOM( 1 , n ^3) s o r t A , u s i n g P a s s o r t k e y s r e t u r n A 15 / 19
  • 15. Proving Correctness of Permute-By-Sorting Lemma 5.4 Procedure Permute-By-Sorting produces a uniform random permutation of the input, assuming that all priorities are distinct. Proof: Go to the Blackboard 16 / 19
  • 16. Permute in Place Randomize-In-Place(A) n = l e n g h t [ A ] f o r i = 1 t o n do swap A [ i ] − A [RANDOM( i , n ) ] Lemma (5.5) Procedure Randomize-In-Place computes a unifrom random permutation. Proof. Go to the Blackboard. 18 / 19