Analysis Of Algorithms University of Bridgeport Analysis of Algorithms


Best case occurs if x = R[mid] is true the very first time. Thus, B(n) = 1 Worst case



Download 3.4 Mb.
Page14/33
Date28.05.2018
Size3.4 Mb.
#51061
1   ...   10   11   12   13   14   15   16   17   ...   33

Best case occurs if x = R[mid] is true the very first time.

Thus,
B(n) = 1




Worst case occurs if x = R[mid] is always false.

Now,


W(0) = 0

W(2k – 1) =
Solving the recurrence equation to get the closed form using repeated substitution,

W(2k – 1) =

= 1 + []

= 1 + [1 + []]

Repeating ‘i’ times,



W(2k – 1) =
if ‘i = k’,

W(2k – 1) = k + 0 = k


We want W(n), so

2k – 1 = n

or, lg 2k = lg (n + 1)

or, k = lg (n + 1) {k in terms of n}
Thus,

W(n) = lg (n + 1)


Download 3.4 Mb.

Share with your friends:
1   ...   10   11   12   13   14   15   16   17   ...   33




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

    Main page