You are on page 1of 2

Unit 22 : searching

t.BIGIDF.FI
.

Linear search
2.
Binary Search

Problem : find -9 in list [03 . . . .


listen D
-

j .
Linearsearch :

Oln)
running time
:
worst case
=

Divideonquermehoa :

worst case running time : 0cm


=

(E) +1
{
" , if n> ,
1- (n) =
otherwise
I,


search left of list Ten) =
2T[É) -11

=
4T (E) +2 =
. . .

search right of list



=
IT (F) the =
. . .

=
ntci) +
log n

=Ñ now ?
check if approach
Then)= T (E) + 1- (E) ✓ correct

=TÉD¥ ) 2910812021

Tcu) =
2T / E) + I


it ( is ;)
ii.
Binarysearch

→ used for E_D lists

l<=xlu1s=nT_
left !
0

suppose 9 > K then


, q is
right of N . • • no need to check side !

thecde : .

whyi.it#rrect?

use # assertion

.IT?.- H*ie-%Ef iciencyofBinarySearch-


%¥g

Tl ?) -11 start with n elements After left


{
, if n> 1
. .
ode comparison ,

otherwise
Ten) After
=
1
,
with 42 . another comparison, left with

E. Takes only 0 Clog n) until


: .

steps one

Ten) =
T (1) +1 element in list .

=T (E) +2 =
. . . .

=T (F) +k =
. . .

now?
1- G) +
login
#
=

=D ( logis)

You might also like