Tutorial 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

QUESTION 1

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.

TRUE OR FALSE CORRECT FORM


O(f + g) = O(f) + O(g)
O(f · g) = O(f) · O(g)
if g = O(f) and h = O(f)
then g = O(h)
5n + 8n2 + 100n3 = O(n4)
5n+8n2+100n3 = O(n2 log n)

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

Is 2n+1 = O(2n)? Is 22n = O(2n)?

You might also like