This preview shows page 1. Sign up to view the full content.
244
Solutions to Review Exercises
cross outs. So the number of basic operations is at most
(l+i) +
... +
(1+
;)
=
(M
1) +
n(
1 +
~
+
!
+
it)
=
M
1
+
nO(logM)
=
y'n
+
nO(~
logn)
=
O(nlogn).
10. Since
n
=
11
=I
1, we set m
=
L
121
J
=
5. Since 5
=
x
=
a5
=
1 and
x
<
are both false, we
replace
n
by 11  5
=
6 and change our list to 2,4,5,8,9, 12.
Since 6
=
n
=I
1, we set m
=
L~J
=
3. Since 5
=
x
output "true" and stop.
This search required three comparisons of 5 with an element in the list; a linear search would have
used two comparisons.
11.
1,3,7,10,12,15
3,7,10,12,15
3, 1, 2
1,2
2
4
4,3
4,
3,1
4, 3,
1,1
4, 3, 1,
3, 1, 1,2,3,7,10,12,15
The algorithm required five comparisons.
12. (a) Here's the bubble sort:
k
=
6: 9,
3, 1,0, 4,5,3
t
3,9,1,0,
4, 5, 3
3,1,9,0,
4, 5, 3
3,1,0, 9,
4, 5, 3
3, f,O,
4,~,
3
3,1, 0,
4, 5, 9, 3
k
=
5: 3,1,0,
4, 5, 3, 9
3,1,0, 4,5,3,9
3,0,1, 4,5,3,9
3,0,
4,~,
3, 9
3, 0, 4, 1, 5, 3, 9

k
=
4 3,0,
4, 1, 3, 5, 9
4, 1, 3, 5, 9
3, 4, 0,1,3,5,9
3,
O,~,
5, 9
k
=
3:
4, 0,1,3,5,9
4, 3,0,1,3,5,9
3,~,
3, 5, 9
k
=
2:
k
=
1:
4, 3,0, 1, 3, 5, 9
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 11/08/2010 for the course MATH discrete m taught by Professor Any during the Summer '10 term at FSU.
 Summer '10
 any
 Graph Theory

Click to edit the document details