Homework #1 for Algorithms

Due: Friday, Jan. 30, 2004

Chapter 1 problems: 4, 11, 22, 25, and the following problems:

A) Analyze the below algorithm to determine the obvious big-oh (upper-bound), then trace the algorithm to determine its theta notation, ( ).

i := n

while i > 0 do

j := 1

while j < i do

< something of >

j := j * 2

end while

i := i / 2

end while

B) Analyze the below algorithm to determine the obvious big-oh (upper-bound), then trace

the algorithm to determine its theta notation, ( ).

for i := 1 to n do

for j := 1 to i do

for k := j to (i + j) do

some code that takes time

end for k

end for j

end for i

C) Analyze the below algorithm to determine the obvious big-oh (upper-bound), then trace

the algorithm to determine its theta notation, ( ).

i := n

while (i >= 1) do

for j := 1 to i do

for k := 1 to n do

something that takes O(1)

end for k

end for j

i := i / 2

end while