Csifinal 5
Csifinal 5
Question 1 [ 2 points] What are the running time complexities of the algorithms in the following
pseudo-code fragments (in big-Oh notation)? Choose the best big-Oh estimate as a function of n,
the size of the input data.
1+1+2+2
nztn
Algorithm AlgoI(A) + .
.
it
Let A be an array of size n
for i 0 to (n 1) do
for j 0 to n/2 do
(
n⇒
a 2 l + 2 t.it
A[i] j*j
end for
( i 121
nz
+ m
if
=
(
.
end for -
.
Algorithm AlgoII(A) +3 + . .
.
+ ( Mti )
Let A be an array of size n
@
the the O ( n4j
iyz
for i 0 to (n ⇤ n) do
1+2
)
= i =
for j 0 to i do
A[j mod n] j+A[j mod n]
LAGAN tent
/
end for
Mount
end for COPYRIGHT
b) O(n2 )
0c) O(n )
4
a) O(n log n) d) O(2n ) e) O(j mod n) f ) O(n2n )
Question 2 [2 points] What is the worst case big-Oh complexity of inserting an element in the
following data structures (as a function of the number n of elements stored in the data structure):
.
4. A 2-4 tree:
a) O(1) 0 b) O(log n) c) O(n) d) O(n log n)