330 likes | 467 Views
Module #19: Graph Theory: part II. Rosen 5 th ed., chs. 8-9. §8.3: Graph Representations & Isomorphism. Graph representations: Adjacency lists. Adjacency matrices. Incidence matrices. Graph isomorphism: Two graphs are isomorphic iff they are identical except for their node names.
E N D
Module #19:Graph Theory: part II Rosen 5th ed., chs. 8-9
§8.3: Graph Representations & Isomorphism • Graph representations: • Adjacency lists. • Adjacency matrices. • Incidence matrices. • Graph isomorphism: • Two graphs are isomorphic iff they are identical except for their node names.
Adjacency Lists • A table with 1 row per vertex, listing its adjacent vertices. b a d c e f
Directed Adjacency Lists • 1 row per node, listing the terminal nodes of each edge incident from that node.
Adjacency Matrices • Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, 0 otherwise. a b c d a a b b d c c d
Adjacency Matrices for pseudo graph • Matrix A=[aij], where aij is the number of edges that are associated to {vi, vj} a b c d a a b b c c d d
Incidence matrices • Matrix M=[mij], where mij is 1 when edge ej is incident with vi, 0 otherwise e1 e2 e3 e4 e5 v1 e2 v4 e3 v1 e1 e4 v2 e5 v2 v3 v3 v4
Graph Isomorphism • Formal definition: • Simple graphs G1=(V1, E1) and G2=(V2, E2) are isomorphic iff a bijection f:V1V2 such that a,bV1, a and b are adjacent in G1 iff f(a) and f(b) are adjacent in G2. • f is the “renaming” function that makes the two graphs identical. • Definition can easily be extended to other types of graphs.
Graph Invariants under Isomorphism Necessary but not sufficient conditions for G1=(V1, E1) to be isomorphic to G2=(V2, E2): • |V1|=|V2|, |E1|=|E2|. • The number of vertices with degree n is the same in both graphs. • For every proper subgraph g of one graph, there is a proper subgraph of the other graph that is isomorphic to g.
Isomorphism Example • If isomorphic, label the 2nd graph to show the isomorphism, else identify difference. d b b a a d c e f e c f
Are These Isomorphic? • If isomorphic, label the 2nd graph to show the isomorphism, else identify difference. * Same # of vertices a b * Same # of edges d * Different # of vertices of degree 2! (1 vs 3) e c Example 11: a more general solution
§8.4: Connectivity • In an undirected graph, a path of length n from u to v is a sequence of adjacent edges going from vertex u to vertex v. • A path is a circuit if u=v. • A path traverses the vertices along it. • A path or circuit is simple if it contains no edge more than once.
Paths in Directed Graphs • Same as in undirected graphs, but the path must go in the direction of the arrows.
Small world • Human relationship as a graph • Stanley Milgram’s “small world” experiment • Stanley Milgram: The Small World Problem, Psychology Today, 1(1), 60-67 (1967) • range = 2-10, median = 5 • http://backspaces.net/PLaw/ • Oracle of Bacon • http://www.cs.virginia.edu/oracle/ • The Erdös Number Project • http://www.oakland.edu/enp/ • Tables in p. 569
Connectedness • An undirected graph is connected iff there is a path between every pair of distinct vertices in the graph. • Theorem: There is a simple path between any pair of vertices in a connected undirected graph. • A component is a maximal connected subgraph. • Connected component, connected subgraph • A cut vertex or cut edge (bridge) separates 1 connected component into 2 if removed.
Directed Connectedness • A directed graph is strongly connected iff there is a directed path from a to b for any two vertices a and b. • It is weakly connected iff the underlyingundirected graph (i.e., with edge directions removed) is connected. • Note strongly implies weakly but not vice-versa.
Paths & Isomorphism • Note that connectedness, and the existence of a circuit or simple circuit of length k are graph invariants with respect to isomorphism. • Examples 12, 13
Counting Paths w Adjacency Matrices • Let A be the adjacency matrix of graph G. • The number of paths of length k from vi to vj is equal to (Ak)i,j. (The notation (M)i,j denotes mi,j where [mi,j] = M.) a b c d a b a b d c c d ab c
§8.5: Euler & Hamilton Paths • An Euler circuit in a graph G is a simple circuit containing every edge of G. • An Euler path in G is a simple path containing every edge of G. • A Hamilton circuit is a circuit that traverses each vertex in G exactly once. • initial vertex is twice • A Hamilton path is a path that traverses each vertex in G exactly once.
Euler path 1 2 3 start finish 4 6 5
Euler circuit 1 2 3 start 7 4 6 5
Hamilton Circuits and Paths • Gray circle is the starting vertex; follow the red lines • removing one edge (dashed line) from a Hamilton circuit makes a Hamilton path • - In some graphs, there are only Hamilton paths, not Hamilton circuits
Module #19:Tree Rosen 5th ed., ch. 9
Trees Uses • Trees are, by far, the most algorithmically and theoretically interesting structure in computer science, since they are used to solve a wide range of problems • Even algorithms themselves are depicted as trees, as can be seen in decision trees and (some) flowcharts (the ones that aren't cyclic) • The usefulness of trees are enormous, and we'll only touch the surface
Definition • A tree is a connected graph with no cycles • E.g., tournament brackets, family trees, organizational charts • A forest is a graph whose components are trees.
Trees: Leaves & Internal Vertices • In the following tree the red vertices are leaves. The other vertices are internal vertices.
Rooted Trees • Sometimes it is useful to distinguish one vertex of a tree and call it the root of the tree. For instance we might, for whatever reasons, take the tree above and declare the red vertex to be its root. In that case we often redraw the tree to let it all “hang down” from the root
Rooted Directed Trees • It is sometimes useful to turn a rooted tree into a rooted directed tree T′ by directing every edge away from the root.
Rooted Trees: Terminology • Some terminology is suggested by family trees. The level of a vertex is the length of the path from it to the root. (The level of the root is 0.) The height of the tree is the length of the longest path from a leaf to the root. • If there is a directed edge in T′ from a to b, then a is the parent of b and b is a child of a. • If there are directed edges in T′ from a to b and c, then b and c are siblings. • If there is a directed path from a to b, then a is an ancestor of b and b is a descendant of a. • A subtree is a vertex and all its descendants “Directed” can be omitted in undirected graphs, but …
(Rooted) Trees: Binary & m-ary • A directed tree is binary if no vertex has outdegree over 2. • A directed tree m-ary if no vertex has outdegree over m • It is more common to call a tree binary if no vertex has degree over 3. • In general a tree is m-ary if no vertex has degree over m+1. • In a rooted binary tree, one can describe each child vertex as the left child or right child of its parent. Left subtree, right subtree
Full, balanced • A rooted tree is a full m-ary tree if every internal vertex has exactly m children. • A rooted m-ary tree of height h is balanced if all leaves are at levels h or h-1 • What is a full, balanced m-ary tree?
Final exam • Slides • Chapter 5 • Sections 1,2,3 • Chapter 6 • Sections 1,2,3 • 6.2 Theorem 6 is excluded • Chapter 7 • Sections 1,2,3,4,5,6 • Chapter 8 • Sections 1,2,3,4,5 • Chapter 9 • Section 1 Chs 8,9 에서 O,X 문제 혹은 증명 문제가 나올 수 있음, 단 8.5 제외