Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Fundamental Concepts on Analysis of Algorithms - Study Guide | CS 4245, Study notes of Algorithms and Programming

Material Type: Notes; Professor: Simon; Class: Analysis of Algorithms; Subject: Computer Science; University: California State University-East Bay; Term: Summer 2001;

Typology: Study notes

Pre 2010

Uploaded on 09/17/2009

koofers-user-23v
koofers-user-23v 🇺🇸

10 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 4245 I. Fundamental concepts 01/08/03
These class-notes were prepared by Saruney Elebiary, and revised by Professor Simon.
1. f : I -> O f (x) An algorithm can be viewed as computing a function
that maps inputs to corresponding outputs.
2. tA : I -> N tA (x) = number of operations algorithm A takes on input
x to termination
3. t’A : N -> N Though the function tA is useful and important conceptually,
in practice it would be more useful to define a function that
measured the performance of the algorithm as a function of
the size of the input n rather than the input x itself.
In general, however, there are many inputs of the same size and
the algorithm may take different amounts of time on these
inputs. There are three common ways to deal with this difficulty
wA : N -> N wA (n) = max { tA (x) | size (x) = n } worst case performance
bA : N -> N bA (n) = min { tA (x) | size (x) = n } best case performance
eA : N -> N eA (n) = p (x) * tA (x) expected time
often p (x) = 1 / | { x | size (x) = n } |
4. f (n) = O ( g (n) )
if there exists a constant c>0 and an n0 N such that
for all n n0 we have f (n) c * g (n)
Examples: f (n) = n17 + 100n2 – 22n(logn)2 + n
g1 (n) = n17 f (n) = O ( g1 (n) ) true
g2 (n) = n20 f (n) = O ( g2 (n) ) true
5. f (n) = o (g (n) )
iff limn-> f (n) / g (n) = 0
6. f (n) = ( g (n) )
if there exists a constant c>0 and an n0 N such that
for all n n0 we have f (n) c * g (n)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Fundamental Concepts on Analysis of Algorithms - Study Guide | CS 4245 and more Study notes Algorithms and Programming in PDF only on Docsity!

CS 4245 I. Fundamental concepts 01/08/ These class-notes were prepared by Saruney Elebiary, and revised by Professor Simon.

  1. f : I -> O f (x) An algorithm can be viewed as computing a function that maps inputs to corresponding outputs.
  2. tA : I -> N tA (x) = number of operations algorithm A takes on input x to termination
  3. t’A : N -> N Though the function tA is useful and important conceptually, in practice it would be more useful to define a function that measured the performance of the algorithm as a function of the size of the input n rather than the input x itself. In general, however, there are many inputs of the same size and the algorithm may take different amounts of time on these inputs. There are three common ways to deal with this difficulty wA : N -> N wA (n) = max { tA (x) | size (x) = n } worst case performance bA : N -> N bA (n) = min { tA (x) | size (x) = n } best case performance eA : N -> N eA (n) =  p (x) * tA (x) expected time often p (x) = 1 / | { x | size (x) = n } |
  4. f (n) = O ( g (n) ) if there exists a constant c>0 and an n 0  N such that for all n  n 0 we have f (n)  c * g (n) Examples: f (n) = n^17 + 100n^2 – 22n(logn)^2 + n g 1 (n) = n^17 f (n) = O ( g 1 (n) ) true g 2 (n) = n^20 f (n) = O ( g 2 (n) ) true
  5. f (n) = o (g (n) ) iff limn-> f (n) / g (n) = 0
  6. f (n) =  ( g (n) ) if there exists a constant c>0 and an n 0  N such that for all n  n 0 we have f (n)  c * g (n)
  1. f (n) =  ( g (n) ) if f (n) = O ( g (n) ) and f (n) =  ( g (n) ) f (n) =  ( g 1 (n) ) CS 4245 01/10/ Chapter 1 Graph Theory: G = (V, E) V - set of vertices E - set of edges each edge is an unordered pair of vertices If xy  E we say that xy joins vertex x to vertex y. Vertices x and y are adjacent if xy  E. The edge xy is incident to vertices x and y and vice-versa. If xy  E x and y are called the end vertices of the edge xy. Kn^ is the complete graph on n vertices, in which every pair of vertices is joined by an edge. En^ is the empty graph on n vertices, in which there are no edges at all. So E^1 = K^1 is called the trivial graph The degree of a vertex x is the number of edges incident to x. Handshaking Lemma: The sum of the degrees of all the vertices of a graph is twice the number of edges. Corollary: The sum of the degrees is always even. If G = (V, E) is a graph G 1 = (V 1 , E 1 ) is a subgraph of G if G 1 is a graph and V 1  V and E 1  E. G 1 is a proper subgraph of G if G 1  G but G 1  G. Ex. G 1 = (V 1 , E 1 ) V 1 = {a} E 1 =  a. E^1 = K^1 G 2 = (V 2 , E 2 ) V 2 = {a, b} E 2 =  a.. b E^2 G 3 = (V 3 , E 3 ) V 3 = {a, b} E 3 = {ab} a .____. b K^2 G 4 = (V 4 , E 4 ) V 4 = {a, b, c, d, e} E 3 = {ab, bc, cd, de, ea} A five-cycle: C^5

CS 4245 01/15/

  1. Edison – Genius is 1% inspiration and 99% perspiration.
  2. Einstein – A theory should be as simple as possible but not simpler.
  3. Mozart – Learn with the masters.
  4. Richard Feynman – Quantum Electrodynamics Physicist Theorem 1: Every graph G = (V, E) is the disjoint union of its connected components. Proof: To prove:
    1. Every vertex x is in some connected component of G. V 1 = { y  V |  an x – y walk in G } G 1 = G[V 1 ] Claim: G 1 is a connected component of G which contains x. X  V 1 since  a walk (the trivial walk) from x to x. G 1 is connected, because…let y 1 y 2  V 1 walk from x – y also  walk from x to y 2 in G. Every vertex of the x – y walk is in V 1 because for every vertex z  x – z walk in G. Similarly, every vertex in x – y 2 walk is n V 1. Since G 1 is induced every edge of these walks is also in G 1 So hence the x – y walk and x – y 2 walk is in G 1 So  y 1 –y 2 walk in G 1. So G 1 is connected.

Claim: G 1 is maximal connected Suppose (by contradiction) : G 1 is not connected So  G 2 such that G 1  G 2 and G 2 is connected. Hence x is a vertex of G 2 Let y be the vertex of G 2 Since G 2 is connected  x – y walk in G 2 So this walk is a walk in G So y  V 1 So G 1 and G 2 have the same vertices Every edge of G 2 is also an edge of G 1 , because it joins 2 vertices of V 1 , and also it is in G 1 , because G 1 is induced. So G 1 = G 2 Hence G 1 is maximal connected. To prove:

  1. Two connected components of G have no vertex in common. Let G 1 , G 2 be 2 connected components of G, G 1  G 2 By contradiction. If not so then Let x be a common vertex. G 1 = (V 1 , E 1 ) G 2 = (V 2 , E 2 ) Let G 3 = (V 1  V 2 , E 1  E 2 ) G 1  G 3 G 3 is connected because if y 1 , y 2  V 3 Then if y 1 ,y 2 are both in V 1 Then  y 1 – y 2 walk in G 1 , hence in G 3. If y 1 ,y 2 are both in V 2 ,

CS 4245 01/24/

A walk from x to y is closed if x = y A cycle x 0 , x 1 , …, xi is a closed walk of length at least 3 such that x 0 x 1 …xi-1 is a path A graph G = (V, E) is bipartite if  V 1 , V 2  V V = V 1  V 2 , V 1  V 2 =  such that every edge joins a vertex in V 1 to a vertex in V 2. Theorem 2: A graph is bipartite iff it contains no odd cycles. Length of a cycle is number of edges of cycle. The distance from x to y in G = dG(x, y) is the length of a shortest path from x to y if one exists, ??? or otherwise. Proof: (=>) Suppose G contains an odd cycle, say x 0 x 1 x 2 … xi And l is odd If G were bipartite, with vertex sets V 1 , V 2 , w.l.o.g. (without loss of generality) let x 0  V 1 So every even # end vertex is in V 1 and every odd # end vertex is in V 2 So x 2 V 2 impossible. since x 0 = xi and V 1  V 2 =  (<=) w.l.o.g. assume G is connected Let x be a vertex. V 1 = { u  V | da(x, u) is even} V 2 = { u  V | da(x, u) is odd} Suppose claim is not true: So  u,v such that u,v  V 1 or u,v  V 2 and uv  E. Since G is connected, clearly V = V 1  V 2

V 1  V 2 = 

In the 1st^ case: d(x, u) and d(x, v) are both even. Otherwise d(x, u) and d(x, v) are both odd In both cases we have a closed walk of odd length. Claim: This partition of the vertices works! In other words every edge joins a vertex in V 1 to a vertex in V 2. Let a shortest path from x to u be x 0 x 1 x 2 … xr = u Let a shortest path from x to v be y 0 y 1 y 2 … ys = v We have x 0 = y 0 = x Since both paths are shortest if xi = yj then i = j Let x’ be the vertex on path x 0 x 1 … xi = u While is also on path y 0 y 1 …ys = v with large index x’ = xi = yj then xi…xr = u v = ysys-1…yi is an odd cycle

Since x 0 x 1 … xl is a path it follows this is a cycle. (2) If G is maximal acyclic then G is a tree. So G is acyclic, so it only remains to show that G is connected. Pick x,y two arbitrary vertices To show  x-y path in G. If xy  E we are done. Otherwise G + xy has a cycle Since G has no cycles, this cycle must include xy Let cycle be x = x 0 x 1 x 2 …xl = y x = x 0 So x = x 0 x 1 x 2 …xl = y is a path in G + xy and l  2 So none of the edges of x 0 x 1 … xl is xy. So this path is in G and we are done. (3) G is tree => G is minimal connected. Since G is a tree it is connected. So it remains to prove that G is minimal connected i.e.  xy  E, G – xy is not connected Pick an arbitrary edge xy, and consider G – xy. Suppose G – xy is connected. So  a path from x to y in G – xy. x = x 0 x 1 x 2 …xl = y has length at least 2. So x = x 0 x 1 x 2 …xl = y x is a closed walk of length 3 in G. Furthermore since x 0 x 1 …xl is a path, it is a cycle. Contradiction since G is acyclic.

(4) If G is minimal connected then G is a tree. G is connected. So it remains to show that G is acyclic. Suppose not. Then G has a cycle. Say x = x 0 x 1 x 2 …xl x 0 l  2 So xl x 0  E. Hence G – xlx 0 is not connected. But x 0 x 1 x 2 …xl is a path in G – xlx 0 Contradiction. Theorem 4: Every non-trivial tree contains a vertex of degree 1. Proof: Suppose not. Then  G nontrivial tree such that it has no vertex of degree 1. Then the minimum degree of G cannot be 0 because G is Connected, so it can have no isolated vertices. So minimum degree is at least 2. So G contains a cycle. Contradiction. Exercise:  nontrivial tree has at least 2 vertices of degree 1.

vuE f(v u) =  (^) uvE f(u v) Max Flow Min Cut Theorem: maximum flow value = minimum cut capacity separating s and t. To prove: (i) f is maximum flow iff (ii) there is no augmenting path in the residual network iff (iii) value of flow f = capacity of some cut separating s and t.

CS 4245 01/29/

G = (V, E) directed s  V source c : E -> R t  V sink f : E -> R (1) xy  E f (xy)  c (xy) (2)  u  V – {s, t} vu  E f (vu) = uv  E f (uv) maximize the flow from s to t value of flow f = sv  E f (sv) - vs  E f (vs) Easy to prove: (exercise) Value of flow = vt  E f (vt) - tv  E f (tv) A cut that separates s from t X  V s  X t  X _ Cut (X, X ) = set of edges that join a vertex in X to a vertex not in X, or vice-versa. The capacity of a cut c(X,X) is defined to be = xy  E, x  X and not ( y  X) c (xy), that is it is the sum of the capacities of all the edges that join a vertex in X to a vertex outside of X. _ Value of f  c ( X, X) Gf = (V, Ef) xy  E Ef = { xy  E | c (xy) – f (xy) > 0 }  { yx | xy  E & f (xy) > 0 } cf (xy) = c (xy) – f (xy) cf (yx) = f (xy)

(2) Compute residual network Gf. (3) Search for an augmenting path. (by breadth first search) If we find it, increase flow and repeat. Otherwise halt, we have maximum flow. Every iteration will cost O (n + m) So O (k (n + m)) k = number of iterations