You are on page 1of 2

COMSATS Institute of Information Technology

Wah Cantt.
Design & Analysis Of Algorithms
Assignment# 1

Class: BS(SE)- 4A,B,C & BS(CS)-4A

Instructor: Samia Riaz

Date :20-Feb-15

Due Date: First Lecture In the Coming Week

Helping Material To solve Assignment:


We used some simplifying abstractions to ease our analysis of the INSERTION-SORT
procedure. First, we ignored the actual cost of each statement, using the constants ci to
represent these costs. Then, we observed that even these constants give us more detail
than we really need: the worst-case running time is an2 + bn + c for some constants a, b,
and c that depend on the statement costs ci. We thus ignored not only the actual statement
costs, but also the abstract costs ci.
We shall now make one more simplifying abstraction. It is the rate of growth, or order of
growth, of the running time that really interests us. We therefore consider only the leading
term of a formula (e.g., an2), since the lower-order terms are relatively insignificant for
large n. We also ignore the leading term's constant coefficient, since constant factors are
less significant than the rate of growth in determining computational efficiency for large
inputs.Thus, we write that insertion sort, for example, has a worst-case running time of
(n2)(pronounced "theta of n-squared").
We usually consider one algorithm to be more efficient than another if its worst-case
running time has a lower order of growth. Due to constant factors and lower-order terms,
this evaluation may be in error for small inputs. But for large enough inputs, a (n2)
algorithm, for example, will run more quickly in the worst case than a (n3) algorithm.

Some rules of thumb

Multiplicative constants can be omitted

14n2 becomes n2

7 log n become log n

Lower order functions can be omitted

n + 5 becomes n

n2 + n becomes n2

na dominates nb if a > b

n2 dominates n, so n2+n becomes n2

n1.5 dominates n1.4

an dominates bn if a > b

3n dominates 2n

Any exponential dominates any polynomial

3n dominates n5

2n dominates nc

Any polynomial dominates any logorithm

n dominates log n or log log n

n2 dominates n log n

n1/2 dominates log n

Do not omit lower order terms of different variables (n2 + m) does not
become n2

Problem Statements:
P1:
i.
ii.
iii.
iv.

P2:

Express the functions in terms of -notation.


n3/1000 - 100 n2 - 100n + 3
n 2 + 5 + 2n
n2 + n+ logn
14n2

Find Running time and Order of Growth of following algo

Min(a[1] a[n])
m a[1];
for c 2 to n
if a[c] < m then
m a[c];

P3: Rewrite the INSERTION-SORT procedure to sort into Descending order


instead of ascending order.

You might also like