Analysis Of Algorithms University of Bridgeport Analysis of Algorithms



Download 3.4 Mb.
Page30/33
Date28.05.2018
Size3.4 Mb.
#51061
1   ...   25   26   27   28   29   30   31   32   33

Example 2: Binary Search
Using iterative approach, the following model can be set up for the average number of comparisons for binary search work.
Assume the total number of elements in an array, n = 2k – 1
Then,

Pr (comparisons = 1) =

Pr (comparisons = 2) =

.

.



Pr (comparisons = k) =

Therefore, assuming element is in array



Average number of comparisons

Solving the numerator, we have







Download 3.4 Mb.

Share with your friends:
1   ...   25   26   27   28   29   30   31   32   33




The database is protected by copyright ©ininet.org 2024
send message

    Main page