Section 8.3
229
Since 5
=
n
#
1, we set m
=
l~J
=
2. Since 7
=
x
>
a2
=
5 we replace
n
by
n
 m
=
3 and
change the list to 7,10,12.
Since 3
=
n
# 1, we set m
=
r~l
=
1. Since 7
=
x
:::;
al
=
7, we replace
n
by m
=
1 and
change the list to 7.
Since
n
= 1
and
x
=
aI,
we output "true" and stop.
This search required four comparisons of
x
with an element in the list; a linear search would have
required three.
(b) Since
n
=
11 # 1, we set m
=
l121
J
=
5. Since 30
=
x
>
a5
=
12, we replace
n
with
nm
=
6
and change the list to 15,17,22,24,30,31.
Since 6
=
n
# 1, we set m
= l*J =
3. Since 30
=
x> a3
=
22 we replace
n
by
n
 m
=
3
and change the list to 24,30,31.
Since 3
=
n
# 1, we set
m
=
r~l
=
1. Since 30
=
x
>
al
=
24, we replace
n
by
n

m
=
2
and change the list to 30, 31.
Since 2
=
n
# 1, we set m
=
r~l
=
1. Since 30
=
x
:::;
al
=
30, we replace
n
by m
=
1 and
change the list to 30.
Since
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '10
 any
 Graph Theory, #, Prime number, The Current, Highways in Croatia

Click to edit the document details