Discrete Structures Homework #10
Due: Wednesday, Dec. 11 , 2002
Section 4.1 exercises 6, 9
Section 4.4 exercises 6
Determine the best big-oh notation for the algorithms listed in the following problems:
A)
for i = 1 to n do
for j = i to n do
something that takes O(1) time
end for
end for
B)
for i = 1 to n/2 do
for j = 1 to n/2 do
something that takes O(1) time
end for
end for
C)
for i = 1 to n do
j = 1
while j < n do
for k = 1 to n do
something that takes O(1) time
end for
j = j * 2
end while
end for
D) (see exercises on page 105 for a useful identity to help solve this)
for i = 1 to n do
for j = 1 to n do
k = 1
while k <= j do
something that takes O(1) time
k = k * 2
end while
end for
end for