- Published on
The Algorithm Design Manual (3rd) Exercise Solution 'E2-50'
Table of Contents
Introduction
This series is my solutions for algorithm exercises in'The Algorithm Design Manual' 3rd edition.
It's my solutions, not model answers, so if you find some mistakes or more sophisticated solutions, please post in comment area below.
Repository
Exercise 2-50
Question
Consider the following algorithm to find the minimum element in an array of numbers . One extra variable tmp is allocated to hold the current minimum value. Start from ; tmp is compared against in order. When , . What is the expected number of times that the assignment operation is performed?
Solution
The probability that the kth element is minimum among the range is .
So, the expected number of times is the summation of probability above from to .
The formula is: