Professional Documents
Culture Documents
8 Prob Analysis and Liner Sorting
8 Prob Analysis and Liner Sorting
Hire-Assistant(A)
1 current ← an infinitely useless dummy
assistant
2 for i = 1..n
3 do if A[i] is better qualified than current
4 then current ← A[i]
5 return current
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Week 8: Prob. Analysis and Linear Sorting CS478
A Cost Model
• Every candidate we interview costs us ci dollars
– c1 dollars fee to be paid to the job agency
– c2 dollars travel expenses of the candidate, …
• General answer:
– We always pay ci ⋅ n dollars for the interviews
– We pay ch ⋅ m dollars for hiring people, where m is the number of
candidates we hire (and fire) in the process
• Best case:
– The first candidate is the best
– Then our cost is ci ⋅ n + ch
• Worst case:
– The candidates show up in increasing order of qualification
– Then we hire every candidate
– The cost is ci ⋅ n + ch ⋅ n
• Abstract problem: Compute the expected number of
candidates we would hire.
Indicator Variables
For an event E, we can define an indicator variable XE = I(E):
Then
Counting Sort
Counting Sort…
Radix Sort