Graph Theory and Algorithm 01 COP 6726: New Directions in Database Systems Graph Theory and Algorithm 01
Basics A graph is a pair G = (V, E) of sets such that E ⊆ [V]2. The elements of V are the vertices (or nodes, or points) of the Graph G. The elements of E are its edges (or lines). A vertex v is incident with an edge e if v ∈ e; then e is an edge at v.
Graphs If all the vertices of G are pairwise adjacent, the G is complete. A complete graph on n vertices is a Kn. Pairwise non-adjacent vertices or edges are called independent. A class of graphs that is closed under isomorphism is called a graph property. If G`⊆ G and G` contains all the edges xy ∈ E with x,y ∈ V, then G` is an induced subgraph of G. The degree (or valency) dG(v) = d(v) of a vertex v is the number |E(v)| of edges at v.
Isomorphism
Subgraph A subgraph S of a graph G is a graph such that The vertices of S are a subset of the vertices of G The edges of S are a subset of the edges of G A spanning subgraph of G is a subgraph that contains all the vertices of G Subgraph Spanning subgraph
Paths A path is a non-empty graph P=(V, E) of the form V = {x0, x1, …, xk} E = {x0x1, x1x2, …, xk-1xk} ,where the xi are all distinct. Two a-b paths are independent if and only if a and b are their only common vertices.
Cycles The minimum length of a cycle in a graph G is the girth g(G) of G. The maximum length of a cycle in G is its circumference.
Connectivity A non-empty graph G is called connected if any two of its vertices are linked by a path in G. A maximal connected subgraph of G is a component of G. The components are induced subgraphs, and their vertex sets partition V. If A,B ⊆ V and X ⊆ V ∪ E are such that every AB in G contains a vertex or an edge from X, we say that X separates the sets A and B in G. A separating set of vertices is a separator. A vertex which separates two other vertices of the same components is a cut-vertex and an edge separating its ends is a bridge.
Non connected graph with two connected components Connectivity Connected graph Non connected graph with two connected components
Connectivity G is called k-connected (for k ∈ ℕ) if G > k and G-X is connected for every set X ⊆ V with |X| < k. The greatest integer k such that G is k-connected is the connectivity k(G) of G. The greatest integer l such that G is l-edge connected is the edge-connectivity λ(G) of G.
Connectivity
Connectivity Block is a maximal connected subgraph without a cut-vertex. Thus, every block is either a maximal 2-conntected subgraph, or a bridge (with its ends), or an isolated vertex. Different blocks of G overlap in at most one vertex, which is the a cut-vertex of G.
Block Tree
Menger’s theorem Let G=(V,E) be a graph and A,B ⊆ V. Then the minimum number of vertices separating A from B in G is equal to the maximum number of disjoint A-B paths in G. A graph is k-connected if and only if it contains k independent paths between any two vertices A graph is k-edge-connected if and only if it contains k edge-disjoint paths between any two vertices.
Tree and forest An acyclic graph, one not contains any cycles, is called a forest. A connected forest is called tree. The following assentation are equivalent for a graph T: T is a tree. Any two vertices of T are linked by a unique path in T. T is minimally connected. T is maximally acyclic. The vertices at distance k from the root have height k and form the kth level of T.
Tree and forest Tree Forest
Tree A subtree of a graph is a subgraph which is a tree. If this tree is a spanning subgraph, it is called a spanning tree of the graph.
Bipartite graphs A graph G =(V,E) is called r-partite if V admits a partition into r classes such that every edge has its ends in different classes.
Matching in bipartite graphs
Complete Graph A complete graph A complete bipartite graph
Contraction and minors
Incidence and adjacency matrices Incidence matrix Adjacency matrix
Basic Graph Algorithm
Depth First Search
Depth First Search Courtesy : https:// goo.gl/QVPy1i Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: B H C G I D E F Courtesy : https:// goo.gl/QVPy1i
Depth First Search A-F A-G Function call stack: A B H C G I D E F dfs(A) A-F A-G Function call stack:
Depth First Search F-E A-F A-G Function call stack: 27 A B H C G I D visit(F) F-E E F dfs(A) A-F A-G Function call stack: 27
Depth First Search E-C E-D E-G F-E A-F A-G Function call stack: 28 A B dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 28
Depth First Search C-A C-D E-C E-D E-G F-E A-F A-G dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 29
Depth First Search C-A C-D E-C E-D E-G F-E A-F A-G dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 30
Depth First Search D-C D-F C-A C-D E-C E-D E-G F-E A-F A-G dfs(D) D-C D-F dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 31
Depth First Search D-C D-F C-A C-D E-C E-D E-G F-E A-F A-G dfs(D) D-C D-F dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 32
Depth First Search D-C D-F C-A C-D E-C E-D E-G F-E A-F A-G dfs(D) D-C D-F dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 33
Depth First Search C-A C-D E-C E-D E-G F-E A-F A-G dfs(C) C-A C-D B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 34
Depth First Search E-C E-D E-G F-E A-F A-G Function call stack: 35 A B dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 35
Depth First Search E-C E-D E-G F-E A-F A-G Function call stack: 36 A B dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 36
Depth First Search E-C E-D E-G F-E A-F A-G Function call stack: 37 A dfs(G) B H C G dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 37
Depth First Search E-C E-D E-G F-E A-F A-G Function call stack: 38 A B dfs(E) E-C E-D E-G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 38
Depth First Search F-E A-F A-G Function call stack: 39 A B H C G I D dfs(F) F-E E F dfs(A) A-F A-G Function call stack: 39
Depth First Search A-F A-G Function call stack: 40 A B H C G I D E F dfs(A) A-F A-G Function call stack: 40
Depth First Search A-F A-G Function call stack: 41 A B H C G I D E F dfs(A) A-F A-G Function call stack: 41
Breadth First Search
Breadth First Search A B C D E F G H I FIFO Queue Closed Nodes
Breadth First Search FIFO Queue Closed Nodes A B C FIFO Queue G H I FIFO Queue Closed Nodes FIFO Queue Closed Nodes FIFO Queue Closed Nodes
Dijkstra Algorithm
Dijkstra Algorithm 2 1 A B C 1 1 1 1 1 D E F 1 1 3 1 G H I A B C D E F Priority Queue ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ Closed Nodes
Dijkstra Algorithm 2 1 Priority Queue Closed Nodes A B C D E F G H I A A B C 1 1 1 Priority Queue Closed Nodes A B C D E F G H I 1 1 D E F 1 1 Priority Queue Closed Nodes A B C D E F G H I 3 1 G H I Priority Queue Closed Nodes A B C D E F G H I
Bellman Ford
Bellman-Ford Algorithm 2 -1 A B C 1 1 1 1 1 D E F 1 1 -3 1 G H I A B C D E F G H I ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
Bellman-Ford Algorithm 2 -1 A B C D E F G H I A B C 1 1 1 1 1 D E F 1 1 -3 1 G H I
Potential Function
Potential Function 1 1 -2 1 A B C D
Potential Function d ( u, v) = d (u, v) – p(v) + p (u) 1 1 -1 1 -2 1 A 1 -1 1 -2 1 A B C D
Potential Function d ( u, v) = d (u, v) – p(v) + p (u) 1 1 -1 A B C D
Take Home Message Basic Graph theory Basic Graph Algorithms