Assignment # 3
Assignment # 3
Most of the exercises below have solutions but you should try first to solve
them. Each subsection with solutions is after the corresponding subsection
with exercises. T
0.01n + 100n2
2n + n0.5 + 0.5n1.25
1
5. The statements below show some features of “Big-Oh” notation for the
functions f ≡ f (n) and g ≡ g(n). Determine whether each statement is
TRUE or FALSE and correct the formula in the latter case.
Rule of sums:
O(f + g) = O(f ) + O(g)
Rule of products:
O(f · g) = O(f ) · O(g)
Transitivity:
if g = O(f ) and h = O(f )
then g = O(h)
2
Which algorithm has better performance in a ”Big-Oh” sense? Work out
exact conditions when these packages outperform each other.
12. Software packages A and B of complexity O(n log n) and O(n), respec-
tively, spend exactly TA (n) = cA n log10 n and TB (n) = cB n milliseconds
to process n data items. During a test, the average time of processing
n = 104 data items with the package A and B is 100 milliseconds and 500
milliseconds, respectively. Work out exact conditions when one package
actually outperforms the other and recommend the best choice if up to
n = 109 items should be processed.
13. Let processing time of an algorithm of Big-Oh complexity O(f (n)) be
directly proportional to f (n). Let three such algorithms A, B, and C
have time complexity O(n2 ), O(n1.5 ), and O(n log n), respectively. During
a test, each algorithm spends 10 seconds to process 100 data items. Derive
the time each algorithm should spend to process 10,000 items.
14. Software packages A and B have processing time exactly TEP = 3n1.5 and
TWP = 0.03n1.75 , respectively. If you are interested in faster processing of
up to n = 108 data items, then which package should be choose?
3
Expression Dominant term(s) O(. . .)
5 + 0.001n3 + 0.025n 0.001n3 O(n3 )
500n + 100n1.5 + 50n log10 n 100n1.5 O(n1.5 )
0.3n + 5n1.5 + 2.5 · n1.75 2.5n1.75 O(n1.75 )
n2 log2 n + n(log2 n)2 n2 log2 n O(n2 log n)
n log3 n + n log2 n n log3 n, n log2 n O(n log n)
3 log8 n + log2 log2 log2 n 3 log8 n O(log n)
4. 100n + 0.01n2 0.01n2 O(n2 )
If it is FALSE then
Is it TRUE
Statement write
or FALSE?
the correct formula
Rule of products:
O(f · g) = O(f ) · O(g) TRUE
5n + 8n2 + 100n3 =
5n + 8n2 + 100n3 = O(n3 )
O(n2 log n) FALSE
6. It is obvious that T (n) ≤ |a0 | + |a1 |n + |a2 |n2 + |a3 |n3 . Thus if n ≥ 1,
then T (n) ≤ cn3 where c = |a0 | + |a1 | + |a2 | + |a3 | so that T (n) is O(n3 ).
7. In the Big-Oh sense, the algorithm B is better. It outperforms the algo-