Review of the Asymptotic
Notation
Egan
fcn qgcn
I A
myquadratic function is any
I Any lenien x x 0C n’I
E Any Cubic x x 0 n
gon
fat Scgins
No
I Anyquadratifunctionisorce
E Any denim a AH
I Any Cubic x x 242
flakolgen
Any quadraticfunction isoti
E Any linear v OM
E Any Cutie or a na
WorstcaseBest
Ocn Gcn 041,047rem
in z si ni i inifiiii f
Exponentialcomponent fashtest
polynomial x J
logarithmic Slowest
T
A BJ
I
f
O
Runs in 0 IET If or0Cm_
iii
Takes 0 Mtn
B S Sisaffattifpt
R
Hot Ho A
r N M A
B A N N A D
B R
R 2 3
R 47 FACT
N If agrapha is
bipartite then it
5th cannotcontain an
oddcycle
level
H
miy O on v
lengthfqote 2 CI i H
odd
our
Ohm
overallcomplexity 0 men to Cmg
0 Mon
Brute force Rem BIS or DFS from each node
CEtimes If all nodes are foundin every
iteration then we have a strongly connected
graph otherwise NOT
Takes 0 ninth
u TO
W
V W are also f through u
s
w
us
01
0 Mtn 1
www am
Discussion 2
1. Arrange the following functions in increasing order of growth rate with g(n) following f(n) in
your list if and only if f(n) = O(g(n))
log nn, n2, nlog n, n log log n, 2log n, log2 n, n 2
2. Suppose that f(n) and g(n) are two positive non-decreasing functions such that f(n) = O(g(n)).
Is it true that 2f(n) = O(2g(n) )?
3. Find an upper bound (Big O) on the worst case run time of the following code segment.
void bigOh1(int[] L, int n)
while (n > 0)
find_max(L, ); //fi d he ma i L[0 -1]
n = n/4;
Carefully examine to see if this is a tight upper bound (Big )
4. Find a lower bound (Big ) on the best case run time of the following code segment.
string bigOh2(int n)
if(n == 0) return “a”;
string str = bigOh2(n-1);
return str + str;
Carefully examine to see if this is a tight lower bound (Big )
5. What Mathematicians often keep track of a statistic called their Erd s Number, after the
great 20th century mathematician. Paul Erd s himself has a number of ero. An one who wrote
a mathematical paper with him has a number of one, anyone who wrote a paper with someone
who wrote a paper with him has a number of two, and so forth and so on. Supposing that we
have a database of all mathematical papers ever written along with their authors:
a. Explain how to represent this data as a graph.
b. E plain how we would compute the Erd s number for a particular researcher.
c. E plain how we would determine all researchers with Erd s number at most two.
6. In class, we discussed finding the shortest path between two vertices in a graph. Suppose
instead we are interested in finding the longest simple path in a directed acyclic graph. In
particular, I am interested in finding a path (if there is one) that visits all vertices.
Given a DAG, give a linear-time algorithm to determine if there is a simple path that visits all
vertices.
r r
00 0
dog
wgn
high n nlglgn.nlgn.ME ne n
fca en gene n
in oci
Ign e
Takes 0 n n
is this a tight bound
C n t C n ly t C n116 t
0 n
nt t t t
21
Bestcase performance is r
I return
0 a
i a a
2 Aaaa
i
n
a nodes are mathematicians
edges show coauthorship
b run BFS from Erdos
c pestre
o
Erdos
q4t