Tutorial 2
Tutorial 2
Tutorial 2
A sorting method with “Big-Oh” complexity O(n log n) spends exactly 1 millisecond to sort
1,000 data items. Assuming that time T(n) of sorting n items is directly proportional to (n log n),
derive a formula for T(n), given the time T(N) for sorting N items, and estimate how long this
method will sort 1,000,000 items.
QUESTION 3
Algorithms A and B spend exactly TA(n) = c1n log2 n and TB(n) = c2n2 microseconds,
respectively, for a problem of size n. Find the best algorithm for processing n = 220 data items if
the algorithm A spends 10 microseconds to process 1024 items and the algorithm B spends only
1 microsecond to process 1024 items.
QUESTION 2
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.
QUESTION 4
Algorithms A and B spend exactly TA(n) = 0.1n2 log10 n and TB(n) = 2.5n2 microseconds,
respectively, for a problem of size n. Choose the algorithm, (which is better in the Big-Oh sense),
and find out a problem size n0 such that for any larger size n > n0 the chosen algorithm
outperforms the other. If your problems are of the size n ≤ 109, which algorithm will you
recommend to use?
QUESTION 5