0% found this document useful (0 votes)
17 views

Graph Tree

Uploaded by

ronniecraig
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views

Graph Tree

Uploaded by

ronniecraig
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
BASIC TERMINOLOGY First, we give some termimology ‘that describes: the-vertices and edges of undise graphs. DEFINITION 1. “fwo-vertices e-and v inan undirected graph G are-calicd cent (or neighbors) in G if {u, v}#s an edge of G. Ife= {u,v}, the edge e is iacident with the vertices u and v. The edge w is also éaid-to connect u and vertices u and v.are called endpoints ofthe edge {u, v}. Pe. —— To keep track of how-many edges are cident to a vertex, we make th definition. DEFINITION 2. The degree of-a-vertex in an undirected graph is the Aga with it, except that.a loop at.a vertex contributes twice to of vertex. The degree of the vertex.y Fedenated-by-denQ). we What are the degrees of the vertices int thegraphs Gand-H displayed in Solution: In G, deg(a) =.2, deg(b) = deg(c)= deg(f) = 4, deg(d) = 3, and deg(g) = 0. In H, deg(a) = 4, fap?) = deg(e) = 6, deg(c es: Rt ill wort \ LOREM 1 The Handshaking Theorem Let G = (V,E) be an undirected graph wit Then - wd -2e = > deg(v). vev € ede. (Note that this applies even if multiple edges and loops are present.) AMPLE 2 How many edges are there in a graph with 10 vertices cach of degrec 6? iA Solution: Since the sum of the degrees of the vertices is 6 - 10 = 60, it follows tux 2e = 60. Therefore, e = 30. a —_ Theorem 1 shows that the sum of the degrees of the vertices of an undirected grat is even. This simple fact has many consequences, onc of which is given as Theorem 2 DEFINITION 4. Ina graph with dirccted edges the in-de; noted by deg” (v), is the number of edges with v as, their term! degree of v, denoted by deg*(v), is the number of edges with v as tal vertex) (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.) i es Find the in-degree and out-degree of each vertex in the graph G with directed cdyes shown in Figure 2. Solution: The in-degrees in G are: deg” (a) = = 2. deg (hb) = 2, deg"(¢) = 3, deg” (d) = 2, deg™(e) = 3, and. deg-(f) = 0. The out-degrces are: deg*(a) = 4, deg*(b) = 1, deg*(c) = 2, deg*(d) = 2, deg*(e) = 3, and deg*(f) = 0. Fi) Since-each ¢dge has an initial vertex and a terminal vertex, the sum of the in- degrecs and the sum of the out-degrees of all vertices in a graph with directed edges are the sazue. Both of these sume are the number of edges in the graph. This result is stated as dhe following theorem. ” eB want PARTITE GRAPHS Sometimes a graph has theproperty that its vertex set can be divided into two disjoint subsets such that each edge connects a vertex in one of these subsets to a vertex in the other subsct. For example, consider the graph representing marriages between people avillage, where cach person is represented by a vericx and a marriage is represented by an edge. In this graph, cach edge connects a vertex in the subset of vertices representing maics and a vertex in the subset of vertices representing females. This leads us to the following definition. (LABEFINITION 5. A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint nonempty sets V; and V2 such that every edge in the graph connects a vertex in Vi and a vertex in V2'(so that no edge in G connects either two vertices in V; or two vertices in V2). In Example 8 we Will show that Ce is bipartite, and in Example 9 we will show thai K3 is not bipartite. ES Ce is bipartite, as shown in Figure 7, since its vertex set can be partitioned into the two sets Vy = (v1.3, vs} and V2 = 42, v4. veh and every edge of Ce connects a vertex 17 V, and a vertex in V2. a LEO 7_- Kis not bipartite. To see this, note that if we divide the vertex set of Ks into two disjoint sets, onc of the two sets must corain two vertices. If the graph were bi too” vertices could not be connected by other vertex by an edge. yartite, these LWO- ‘an edge, but in K3 cach vertex is connected to every REPRESENTING GRAPHS ; he (One way to represent a graph without multiple edges is to list all the edges of this Braph. Another way to represent a graph with no multiple edges is 10 usc adjacency lists, which specify the vertices that are adjigggt t0 each vertex of the graph) VNAMPLE 1 Use adjacency lists to describe the simple graph given in Figure 1. Solution: Table 1 lists those vertices adjacent to each of the vertices of the graph. EXAMPLE 2 Represent the directed graph shown in Figure 2 by listing all the vertices that are the terminal vertices of edges starting at cach vertex of the graph. sc 1 TABLET An Edge List for TABLE 2 An Edge List fora Simple Graph. Directed Graph. \ aa, Vertex | Adjacent Vertices Initial Vertex Terminal Vertices | a e a | bade b : b | bd c © b ace * d a { e e bed _ ke 4. Solution: Table 2 represents the directed graph shown in Figure 2. (AADIACENCY MATRICES Carrying out graph algorithms using the representation of graphs by lists of gdges, or by adjacency lists, can be cumbersoune if there are many edges in the raphe mplify computation, graphs can be represented using matrices. Two types of my cod ede monly used to represent graph: be p We adjacency of vertices, and the other is baéed on incidence of vertices and edges. suppose that G = (V, E)isasimple graph where |V| = n. Suppose that the vertices of listed arbitrarily as 1,2... ra ‘The adjacency matrix A (or Ag) of G, with to this listing of the vertices, is the m X n zero—one matrix with I.as its (, jth pare when v and v, are adjacent, and 0 as its (i, j)th entry when they are not adjacent. In other words; if its adjacency matrix is A = (ai), then ts if tv:. vid is an edge of G, : ai will be presented here. One is based on thi EN AMPLE A EXAMPLES Graph with the m Adjacency Matrix. ¥XAMPLE S HGR a Pscudograph. Use an adjacency matrix to represent the graph shown in Figure 3 Solution: We order the vertices as a,b, c,d. The matrix représenting this graph is arid 1o19)d 1100 1000 3 Draw a graph with the adjacency matrix “fo 1.10 1001 1001 0110 ~ with respect to the ordering of vertices a, b, c, d. Solution: A graph with this adjacency matrix is shown in Figure 4. 0 Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges. A loop at the vertex a; is represented by a I at the (i, i)th position of the adjacency matrix. When multiple edges are present, the adjacency matrix is no Jonger a zero-one matrix, j, Jyth entry i equals the number of edges iated to {aj, aj). extn undirécted graphs, including mn!:igraphs and pscudographs, have symmetric adjacency miatrices. Use an adjacency matrix to represent the pseudograph shown in Figure 5. Solution: The adjacency matrix using the ordering of vertices a, b, c,d is 0 30 2 3B 011 O11 2)° 2120, : We used zero-one matrices in Chapter 6 to represent directed graphs. The matrix fora directed graph G = (V, £) has a 1 in its (i, j)th position if there is an edge Ata tov, where vy, Yq is an arbitrary listing of the vertices of the directed graph. In uiher words, if = [aj,) is the adjacency matrix for the directed graph with respect '° this hating of the vertices, then a, =[' if Ours an edge of G, © otherwise. XAMPLE 6 7 ane AMPLE 7 INCIDENCE MATRICES ~~ {-Another common way to represent graphs i 9 ueoiRMiiitieg matrices(etG = BE) bean undirected graph. Suppose that v1, v2,..., vs are the vert the edges of G. Then the incidence matrix with r are rveten te edges of han i idee rix with respect to this ordering of V and E is mm = {1 When edge e, is incident with », 0 otherwise. . Represent the graph shown in Figure 6 with an incidence matrix. Solution: The incidence matrix is ca ‘ ce 6 es 6 66 ; oP Late 0°08 080 wees nfo o 1 104 vg {0 0.0. OY ASSL: oa InBie Ore skaeri9 na070 ie [Or te 08 Ae 20 a Incidence matrices can also be used to represent multiple edges and loops. Multiple edges are represented in the incidence matrix using, columns with identical entries, since these edges are incident with the same pair of vertices. Loops are represented vs:n8-¢ column with exactly one entry equal to 1, corresponding to the vertex that is incident ‘with this loop... Represent the pseudograph shown in Figure 7 using an incidence matrix. ENAMPLE { Coa A genealogical chart of the Bernoullis, a famous family of Swiss mathematician shown in Figure I. Such a chart is also called a family tree. A family tree is a where the vertices represent family members and the edges represent. parent: relationships. The undirected graph that represents a genealogical chart is an exi of a special type of graph called a tree. A tree is a connected undirected graph with no simple circu Since a tree cannot have a simple circuit, a tree cannot contain multiple edges orl Therefore any tree must be a simple gruph. Which of the graphs shown in Figure 2 are trees? Solution: G, and G2 are trees, since both are connected graphs with no simple cl s Gj is not a tree because ¢, b, a, d, ¢ is a simple circuit in this graph. Firtally, Gs a tree since it is not connected. phs d Any connected graph that contains no simple circuits is a tee. What about gra cal re Oe taining no simple circuits that are not necessarily connected? These graphs art THEOREM 1 Nikolaus r (1623-1708), wo was ee ( aaa are ee et ceo aes (0687-1759) (1695-1726) (1700-1782) _ (1710-1790) / \ Johann It —_Jackob IT (1746-1807) _ (1759-1789) FIGURET The Bernoulli Family of Mathematicians. forests and have the property that each of their connected components is a tree. Fig- ure 3 displays a forest. ‘Trees are often defined as undirected graphs with the property that there is a unique simple path between every pair of vertices. The following theorem shows that this. al- ternative definition is equivalent to our definition. ‘An .undirected graph (any.t9 of its vertices. if and:only, if there is. unique aad: path between | Proof: Firstassume that Tis atree. Then Tis a connected graph with no simple circuits. Let x and y be two vertices of T, Since T is connected, by Thegrem | of Section 7.4 there is a simple path between x and y. Moreover, this path must be unique, for if there were a second such path, the path formed by combining the first path from x to.y followed by the path from y to x obtained by reversing the order of,the second path from x to y would form a circuit, This implies, using Exercise 35 of Section 7.4, that there is a Gi t FIGURE? G, and G; Are Trees descendants of a vertex » are those vertices that have v as an ancestor. A Vencx OF tree is called a leaf if it has no children Vertices that have children are called internal wertlees. The root is an intemal vertex unless itis the only vertex in the graph in which case it is a leaf. If a isa veriex in a tre, the subtree with a as its root is the subgraph of the tree consisting of a and its descendants and all edges incident to these AMPLE 2 Inthe rooted 1ee 7 (with oot) shown in Figure 5 find he parent of he She ot : w~*t the siblings of h, ull ancestors of ¢, all descendanis: ‘of b, all internal vertices, and all leaves. What is the subtree rooted at g? and j. The siblings of h are of b are c, d, and. The k,l, and m. The subtree a s Solution; ‘The parent of ¢ is b, The children of g are fi, i and j. The ancestors of e are c, b, and a. The descendants internal vertices are a, b, c, g, h, andj, The leaves are d, €, fds rooted at g is shown in Figure 6. .ét their internal vertices have the same num- ations. Later in this chapter we will and coding. Rooted trees with the property that all ber of children are used in many different applic: use such trees to study problems involving searching, sorting, IN 2. ‘A rooted tree is called an m-ary tree if every internal vertex has Idren, The tree is called a fill m-ary tree if every internal vertex rary tree with m = 2 is called a binary tree. ‘clemouly lowe, atmos A chtldrew & Hee Since eck chemi ow a brow Vee have, 2. childven , left se eee wget a. DEFINITIO! no more than m chil hhas exactly m children. ‘An m- P tree chose called a binoy Bioauny Tree eof ™ a ‘ i FIGURES A Rooted Tree 7. FIGURE 6 The Subiree Rooted Atg-

You might also like