[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
2.5
Divide Conquer
binary search:
only compare once, just
avoid s+e overflow.
s will catch up e in the end, then break while loop
check a[m] == k outside of while
while
(
s
<
e
)
{
//
m
=(
s
+
e
)/2;
m
=
s
/2+
e
/2
+
s
&
e
&1;
if
(
a
[
m
]<
k
)
s
=
m
+1;
else
e
=
m
;
}
if
(
a
[
m
]
==
k
)
return
ture
;
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]