

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Cleave; Class: Combinatorial Computing; Subject: Mathematics; University: Eastern Illinois University; Term: Spring 2009;
Typology: Study notes
1 / 41
This page cannot be seen from the preview
Don't miss anything!


































I (^) Tree-based searches abound in applications, and are amenable to computerized solutions.
I (^) Depending upon the application, we may wish to nd
I (^) To organize the enumeration of possible solutions:
I (^) The big challenge is to be sure to check that all possible ways to generate a solution are investigated: that the enumeration of possibilities is complete.
I (^) numbers will indicate visitation order
I (^) dotted lines will represent unmarked edges
I (^) use alphabetic order to choose among next nodes to visit
a
b
c
d f^
i
g
h
Given : An undirected graph G = (V , E ), and a vertex v ∈ V Goal : Visit all vertices and edges of G starting with v.
I (^) Recall:
deg(v) = 2jE j, i.e., the sum of the degrees of all nodes is twice the number of edges.
I (^) For any v, DFS(G , v) is called exactly once ó when v is unmarked.
I (^) So, if < v, w > is an edge, it's visited and marked at that time by DFS(G , v) or DFS(G , w), whichever node is visited rst.
of 2jE j times over all calls of DFS.
I (^) As for marked edges: Claim : DFS(G , v) marks edges which form a tree with root v. [Proof by induction on number of unmarked vertices in G .]
If T is the tree formed by DFS (G , v), then for each edge e ∈ EG , either I (^) e ∈ T , or I (^) e connects a vertex in T to some ancestor or descendent in T. I.e., there are no cross–edges in T.
Proof. Let e = < u, W >. if u is marked rst, then w is marked during DFS (G , u). So, by the previous lemma (vertices are visited only once), w is a descendent of u.
I (^) Suppose we don't want to visit all the vertices ó we merely want to nd one with a certain property: i.e., we want to be able to stop.
I (^) Idea : nonñrecursive version of DFS using a stack.
I (^) We'll assume we're not interesting in visiting every edge.
Works the same as for undirected graphs, but there are differences with respect to the DFS tree ó it may not be a tree, but a forest.
There are four possible types of edges in the DFS forest:
I (^) the tree edges: of the DFS tree
I (^) back edges: edges to ancestors in the tree
I (^) forward edges: edges to descendents in the tree
I (^) cross edges: all others
Suppose there is a directed path v 1 ; v 2 ; : : : ; vn in G such that v 1 has lowest DFSnumber in fv 1 ; : : : ; vn g. Then, ∀ 1 < i n, vi is a descendent of v 1.
Proof:
Note v 1 and all descendents have DFSnumbers in the interval [a..b], and DFSnumber(v 1 ) = a.
Proof will be by induction on the number of nodes in the path.
BC Let n = 2, and v 1 → v 2. By the last lemma, v 2 is a descendent of v 1.
IH Assume for directed paths with n 1 nodes where v 1 has lowest DFSnumber, that v 2 ; : : : ; vn 1 are descendents of v 1.
IS Show lemma is true for paths with n nodes. If vn is not a descendent of v 1 , and the DFSnumber(v 1 ) > DFSnumber(vn ), then DFSnumber(vn ) >DFSnumber(vn 1 ) since vn 1 is closer to v 1 in the path (and hence will be processed before vn ).
I (^) Suppose a program consists of many procedures.
I (^) Let us say procedure X depends on Procedure Y if there are procedures X = X 1 , X 2 ,... , Xn = Y such that Xi calls Xi + 1 ∀ i < n.
I (^) Question: Does any procedure depend on itself?
I (^) Why care?
I (^) As programmers, this is a sort of recursion I (^) As compiler writers, we can allocate one big activation record for all the procedures if none depend on themselves.
I (^) Consider procedures as vertices of a directed graph, and X → X′^ if X calls X′
I (^) We want to know: does G contain any directed cycles?
I (^) Theorem. let G = (V, E) be a directed graph, and let T be a DFS tree (forest) of G. Then G contains a directed cycle IFF T contains a back edge.