You are on page 1of 42
OP Of data, Vatious other ar BFaph of functions oF all World situa duct mical sin cle, ro oso Ucture of a molecuie, organization charts, com LEARNING OBJECTIVES Afier studying this chapter, you should be ‘able to * understand and usé man ¥y terms associated with a simple graph and directed understand the use of graphs as representation tools in a variet Prove whether or not two graphs are isomorphic use Euler's formula for a simple, connected and plannar graph. use directed, undirected or multigraph graphs to represent in computer memory. ty of context INTRODUCTION | Graph theory is used to analyse problems of combinatorial nature that arise in computer science, operations research, physical sciences and economics. The term graph is familiar to you because it has been used is the context of straight lines and linear inequalities. The graphs are used to represent a problem involving discrete arrangements of objects that are related to each other, but without taking into consideration their internal properties. In this chapter, first we will combine the concepts of graph theory with digraph ofa relation to define a more general type of graph that has more than one edge between a pair of verte Second. we will identify basic components of a graph, its features and many applications of graphs. THEORY CHAPTER 9 9.2 (BASIC TERMINOLOGY ) inthis seotion definition of graph and basie ermrinology with elementary properties of graphs are presented. 9.2.1 _ Graph Ever written as G = G (i) The finite set of ver (\; E) consists of to component led points (nodes, oF junctions), and {an The finite set of (directed) edges B, also called Fines or ares connecting pair of verte Linother words, in @ graph there is a mapping from the set of edges Eto the set of vertices V such pene ie associated with ordered or unordered pair of elements of Jn other words, each edge, that eac + unordered pair of vertices (0, vj) where v, and vy, are called end vertices of v ¢, 18 associated with an »s V, also ca A graph is said to be the directed graph or digraph if it is roakrat to associate a direction with each edge of the graph. That is. edges are ordered pairs of distinct vertices. A directed graph can be regarded as fay road where traffic flow is permitted in only one direct ion directed arc (i, ) permits flow only from vertex i 0 j. Figure 9.1 {provides an example of a directed graph on v; vs} with E = {(¥, Vo)s (Vp V3) (as Va)s } ion of an edge is Fig. 9.1, Directed Graph on v= ty Va (a. V3) (Wye V5)+ (55 Vg)s (gy Vg)}- The dire shown by placing a directed arrow on the edge] Each pair of vertices connecting with an edge is called the end points. If there is only one edge between nwo vertices, say v, and v,, then we often identify an edge, say e, with the set {v,, vp}. Thus in set theory terminology we write the set of edges, E = {(v,, Vp); (¥ys V3)s (Vas V3); (V5: Va)s (Wss Va)s (Way Vals (Vay ¥5)} as the ordered pair of elements of the set of vertices V (also called arcs), where first element is called the origin or source of the edge (v, v)) and second element is called terminus or terminating verte} In specifying any edge of a digraph by its end points, the edge is understood to be directed from the Source vertex towards the terminating vertex. But if there is more then one edge between two vertices, then different edges are identified with labels such as 0 and 1 as shown in Fig. 9.2. M2 avs Usually in a graph G we denote the number of vertices by and the Humber of edges by m. If, as in the most applications, the values of both m and » are finite, G is said to be a finite grap’ Jn place of circles, vertices in a graph are also represented by using dots. Usually names of edges in a graph are omitted because they have {O.ntinsie meaning. As usual, an edge between a pair of vertices is “sed to record information abo Hionshi i et ct reamed ut the relationship or connections between Fig. 92 Directed Graph » ie ie indegree of a vertex v in'a directed graph is the number of edges ending at it, and is denoted indeg (v), : yeu DISCRETE MATHEMATICS uutdegree The outdegree of a vertex y in a 4 directes s . outdeg (v),) “eted rept isthe Humber of edpes in PEF OF edges bey nin inning Mustration In Fig. 9.2 the indegrees 4 From (fs ; is © indegrees and outdegrees of various Vertices "eg Vertex : vt 5 ¥, % : ae a8 index, Indegree —; 0 2 4 2 ' Outdegree : 2 2 0 1 Dogree of a vertox The degree of a vertex denoted by Av) oF deg (v connected with it 218 the number of ey, ay As shown in Fig, a have degree 3 each, v Finite graph A graph G(V. E) is said to be finite graph if it Sontains finite number of edges and vertices (or has an even number of vertices with odd degree). This result will be proved , latter. FG (V. E) is finite, then V (G) denotes the number of vertices d Ns in G and is called the order of G and E (G) denotes the number of . i edges in G and is called the size of G. Fig, 93 A vertex is said t0 be an even vertex when its degree is even, otherwise an odd vertes In Fig. 54 vertices 3 and S are odd vertices, whereas vertices 1, 2 and 4 are even vertices se the vertex a has degree 5, vertices ¢ and (a eX b has degree uf \ Pendant vertex A vertex is said to be pendant vertex or an end vertex if its degree is one. "For example, in Fig. 9.3 we have deg (a) = 5, deg (6) =2, deg (c) = 3, deg (d) =3, deg (e) = 1 (pendan vertext), deg (f) = A vertext is said to be isolared if its degree is zero or vertex has no incident edge. For example, i Fig. 9.3, vertex fis isolate Theorem 9.1 1fG (V, E) is a directed graph, then the sum of the outdegrees of the vertices of a diagraph equals the sum of indegrees of the vertices which equals the number of edges in a diagraph, ic. E indeg (v) = E outdeg (v) = e for all ve V. Proof The proof of this theorem is obvious. As shown in Fig. 9.2, the sum of the indegrees equals the sum of outdegrees which also equals the number of edges in the diagraph DiGirem 9.2. Prove that the number of vertices of odd degree in a graph isyalways even. Proof Consider a graph having vertices of even and odd degrees. Then the sum of degrees of all vertices can be expressed as the sum of even degree vertices and odd degree vertices. That is Edewly) = ¥ dew(y) + Ldew(vy) mH a even . sai : is on Since the sum of degrees of all vertices is even, the left side of above equation is even. ee the RHS, the first sum of j vertices is even. Thus for the second sum to be even, the number be even. Hence, the result is proved. CHAPTER 9 GRAPH THEORY 261 ons In Fig. 9:3, + of degrees of all vertices is even, i.e. deg (v) = deg (a) + deg (b) + dog (¢) + de 8 (d) + deg (c) + de =54+ 243434140514, $8 (6) + dew (f) mber of vertices of odd degrees 5, 3, 3 and 1 are 4, which is ices of odd degree. is even. Hence, wo nustrati ‘The sum ‘The nt of veri cent vertioes (OF nodes) Two vertices are said to be adjacent if they Fs 4 (i ee cted by an edge. I there isan edge, e= (u,v) connecting vertices are conte wand V ape called adjacent to each other and also called end : wage athe vertex u is said to be adjacent to v whereas v perjacert from U- AlSO the edge e is called incident with the vertices u, jv it connect on its end points.\In Fig. 9.4, vertices 1 and 2 are adjacent ant ps. Vetoes 1 and 5 are nt adjacent 3 422 Undirected Graph & undirected graph is also defined in the same manner as directed graph except that edges (or arcs) are “mnordered pairs of distinct vertice’. | Figue 9-4 is an example of an undirected sraphfin an undirected graph we can refer to an are joining the vertex pair u and v as either (u, v) or (¥, u). An undirected arc (u, v) can be considered as a two-way road with traffic flow permitted in both directions either from vertex u to v or from v to u. An edge such vy stands for {(u, v), (¥, w)}. Although (u, v) = (¥, u) only when u = v. e have even number rand V. the sints of th Fig. 9.4 Undirected Graph as (u, Theorem (Handshaking) Theorem 9.3 If G(V, E) is an undirected graph with e edges, then sum of degrees ofthe vertices in an undirected graph is even, i.e. E deg (v) = 2¢ for all ve V. Proof Since degree of a vertex is defined as the number of edges (or ares) connected with it, therefore, the sum of the % degree counts the total number of times an edge is connected (incident) with a vertex. As every edge is connected with exactly two vertices, so each edge is counted twice at each of its end. This implies that the sum of the degrees equal twice the number of edges, : Fig. 9.5 aff loop isthe edge in a graph whose end points are same) ie. itis an edge from a vertex to itself. A loop; contributes 2‘to the degree of a vertex. In Fig. 9.5, edge ie vertex 5 forms a loop, and degree of vertex 5 is 3. 423 Simple, Multigraph and Pseudo Graph] i i {one daa or undirected graphs, there exists certain pair of nodes that are eee 9.5; the ae d edaes are called multiple or parallel edges! For example, in diagraph shown In 18. Gis ayn’ @2 ae multiple or parallel edges because these edges connect the same end Poms os well Sop since its end points are at the same vertex} A diagram which contains multiple edges joined by more than one ne lcops is called a mutigrap i j 262 DISCRETE MATHEMATICS A Staph _in which loops and multiple edges are allowed is called pseudo graph\Fig. 9.6 is an example of such graphs. i Parallel edges Two or more edges e fon ige5 "Two or more edges in E of the form (vy v,) and (v,,v,) are parallel if and only if v graph which has neither loops nor multiple edges is called a simple graph Fig. 9.7 (a and b) are examples of simple undirected graphs bee these contain no loop and the edges are all distinct, Example 1 Show that the graph in Fig. 9.6 is not a simple graph, Fig. 9.4 Solution As por definition, a simple graph is one which does not have multiple ed shown in Fig. 9.6 contains a loop formed by the edge e, whose end points are the oO" The more than one vertic 1d e3 connect the same vertices v and vs. Hence, graph ste % Al not a simple graph. s Shown in Figg, |Examaté 2 Describe the graphs shown in Fig. 9.7(a) and Fig. 9.7(b). v1 % BT Yq 4 Vy 2 V3 Fig. 9.7 (a) Fig. 9.7 (6) Solution (i) The graph G (V, E) shown in Fig. 9.7(a) consists of 4 vertices and 5 edges as given below V = (Vp, Vg Vyr Vg} and -E = {(vp, Vp)s (ps V5)s (Vas Vabs (Vos Vals (Wes Vg) (ii) The graph G (V, E) shown in Fig. 9.7(2) consists of 5 vertices and 6 edges as given below: V= (Vp Von Vy Vg Vg} amd E= {(vy, V4), (Wap Vy)s (Wa> Vgbs (Vay Val (W3s V3) (Ys ‘(ost Draw a diagram for each of the following graph G (V, E). (a) V= {a,b cde, f}, B= {(ad), (aS) 6, 0), 6S) (6 9} (0) V = {a,b, c,d}, B= {(a, a), (b 0), (b, 4), (6 4) (6 a), ( @)} (0) V = {a,b,c,d,e}, B= {(a,d), (b, 0), (b, d), (b &), (4, 2), (CF Solution First draw vertices of the graph and then indicate edges by connecting the appropriate verses of the graph as shown in Fig. 9.8(a), (b) and (c). a Diet ae e fab wattes: owe a 258 es e4 la &4 a ° Y Sere a ae ‘ @ o o] Fig. 9.7 CHER ea ORAPH THEORY. 26: Erampla 4 (a) Find the degree oF exch VerteN in the MUTKEEAPH shou iy Pip y 3 5.99, (6) What is the degree 0! % 7 Solution (a) The number of edges associated with vertex in Fi 9.9 determine 2 its degree. So we obtain deg (v,) = 2, dep (Vy) ™ Note that the loops at vy and No the vertex, a, dee (4) > 5. dee (4) = 1, deg Cy) = 3, counted twice to determine degree of idl to be isolated if it docs not associated (or (8) Since a vertex is | connected) with any edge. therefore deg (v2) = 0. aph G (V, E), where V = {¥j, Vp. vy} and deg (v,) = 4 Example 5 Consider (a) Does such If not why? (6) Does such a multigraph G exist? If yes, give an example, Solution (a) Since there can be only one edge from vertex v, to each ofthe other two vertices and multiple edges and loops are not permitted in a graph, therefore, such a graph does not exist, and hence deg (v 22 (d) A maltigraph with E = {(vy, V2); (Vp) V2) (Vay Va)s (Was ¥3)} exists. 9.2.4, Walk \ Tet u, v be (not necessarily distinct) any two vertices in ah undirected graph G (V, EN) A walk wv in G is the loop-free finite alternating sequence U= Vg, 15 Vys €p» Vas &35 «+5 Eps Vp 41 Gqp Yq = ¥ OF Vertices d eddes starting at vertex v, and ending at vertex v, involving the n edges e,= {v,_",v)) for 1 < faltemately a walk is a sequence of vertices and edges that begins at v, and travel along edges to v, 30 ‘Hat no edge appears more than once| However, a vertex may appear more than once. Fig. 9.10 (a) and (5) illustrate two walks in this graph: 1-2-3-4 and 1-2-4-5-2-3. fins walk, first and last vertices in the sequence are called terminal vertices. Closed and open walk A walk is said to be the closed walk if it is possible that a walk begins and end at the same vertices, i.e. v; = vj (and n > 1), Otherwise the walk is called open, i.e. terminal vertices are different] [25h CYCLES AND CONNECTIVITY “/ oe. [A path is a walk through_a sequence, Vo, V4, V2. ‘any repetition of vertices, If there exists a path from vertex va to v,, in an undirected graph, then there always evists a path ft ¥,, to vy toof But in directed graph, it is not necessary that there e: path from y,,t0 vo also. The walk shown in Fig. 9.10(a) is'also a path, but the walk shown in Fig. 9.10(b) is not a path because vertex 2 is repeated twice in it. , v,, of vertices, each adjacent to the next, without om «@ ( Fig. 9.10 Examples of Walk maid to be the fonvard edge i the path passes through vertex i prior to wn o OF tO Passi {ates fof a path can be divided into wo groups: forward edges and hackwant (Jina path is sand ¢ and is said backward edge otherw (2. 3) are forward edges and the edge (5, 2) is a ba h that does not involve a repeated edge. Thu, % An " tye ple, in the path shown in Fig, 9.10(), the edges qh! Mes (1,2) ang ckward edge. ce] For e 2. (A sail from a vertex u to v is @ i a path of the form: 4 all from uy UW Voy Cys Vs Cry oes Gye ts Yan Sar Ma where all ¢; are different R.A simple path from u to v is theone in which ‘no edge is repeated in.the path] That a3 ple pak < also 3 trail where all the vertices and all edges are different except the first vertex is equal ae path is also called an elementary path if no vertex is repeated more than once in the path) er of edges in a path is called the length of the path) The scquence of Which each pair of vertices is sn edge of the graph, is of length 1. loop is a path of length one. A loop can be included in a walk but notin a fh the terminal vertices are of degree 1 when other vertices (also called 1 2 IS @ Fig. 9.11 Examples of Path verte {[enstn of path The numb > 1 vertices of a graph ‘an edge which is not 3 pallijas shown in Fig. 9.11LIn a pat intermediate vertices) are of degree 2. 1 2 5 @ 4 4A cireuit is a closed walk (or path) of non-zero length that contains no repeated edge where stat and end vertex is samelive. u = vy =v, and alle, are distinct. for Ets Vas Cay +05 Ege Vy = Where Vo nes examples a“ a able 9.1 summaris an open walk. Furthermore, every ¢: in tum is . ja closed walk. sit will always imply the presence of at fa c, then the walk is called an Wy path, tw fe erm eyele will always imply the pre fmples oF cteuits. A -citeuit is algo cealled circidar pa 91D ES above definitions. From th CHAPTER 9 GRAPH THEORY 265 | Iho vertex of the wv walk occurs | \. then such closed path is described by the 1 OF least three distinct edyes, Fig. 9.1200), (hy ih clemennary evele, polygon or eve te] <> Oo or nples of Circuits ANE ONE edge ox © comparison, appears that a path is a trail, which and every circuit with at least two edges rable 9.1 E ia Repeated Vertex Repeated Edge Starts and Ends at the Same Vertex Trail Yes No Yes Circuit ‘Yes No Yes Path ‘+ Simple No No No * Closed Yes Yes Yes Cycle No No Yes ] Walk A) [_Eeees, vertices may be repeated ‘Open Walk Closed Watk Initial and final vertices are different J ‘Trial ages are not repeated 2 ae Path Verices are also not repeated Fig. 9.13 Walk, Tr Initial and final are vertices same Cireuit iges are not repeated yale also not repeated except Vertices a al, Circuit, Path and Cycle Relationship 4 wey se va) = 9 Or 5 (We) - 2 . / 266 Discrere matnemanics \Y* * 9? V6) 2 04 ent vertices" (a) Pendent vertices V7 (by Penulemt edges ©4CVs, v,) ices (VV Veo) (a) Even verti (0) Odd vei 3. Cava) ide 5 yralar sate st i Incident. edues Foes 7) Adjacent vertices Solution (a) Since vertex v, is of degree one, therefore it ig pendent vertex (6) The edge (vg. V5) is incident with pendent vertex v5, &4 therefore it is pendent edgy a (c)_ Vertices having odd degrees are vy, ve and v,. 7 (c)_ Vertices having odd degrees are v,, vg and vg. Thus, these vq are odd vertices. vert (a) Vertices having even degrees are vj, vy, and vy, Thus, 9.14 All 9 edges in Fig. 9.14 are incident edges @ cach af tiem le ig edges because each of them is connected witha pre of, (/) Vertex xy is adjacent 10 vg and vgi Vertex vy is adjacent to vy and vs, adjacent to v, and vy; Vertex v, is adjacent to vy. Vg. Vertex ve is adjacent to v, and vy. Vertex vs is adjacent to v, and c | ample 7 Let G be a graph shown in Fig, 9.15. Find all simple paths from % Vertex v, to v; and also find the length of the shortest path. Solution A path from veriex v, to v will be called simple if no vertex is repeated. There are only two simple paths from vertex’ v, to v3: {Vj5 V4y Vss V3} and {Vj. Vay Vp Vg V5) Also, (V;, 3, since 3 is the length of the shortest path from v, to Y5 V4 Vs ‘6 Fig. 9.15 [esamole 8 Consider the multigraphs shown in Fig. 9.16(a), (6) and (c): Determine which of them are (a) connected, and (6) graphs. Solution (a) Since only in graph shown in Fig. 9.16(c) there is a path between any two vertices, therefor, it is connected. Rest are not connected. (6) All of them are graphs. A (6) @ ; a f o_| ‘ 267 | = ? Consider the multigraphs shown in 14 + aan (p) loop fre Soa) Since only 94700), Vane ¢ and (e) straphs Vand (0) Determin which af them are (a) muttigeaphs shown in Pig. 9 4 (9) and Oh) there j © connected, * path between any two nigrph shown iO FIR BATT IW 8 TO0D, Le a8 edge wit o cy MATT a.174a) amd (A) ate graphs, The mute only be own in Pig. 2.1702) has multiple raph st Haph shown in Pig Hes and a loop EO Meni Ly MMe o 6) © Fig. 9.17 a3t ‘ome Undirectes@raphs.) i F'sid to be connected if there exists at least one path between every pair of its verti te. fa any veri from any other vertex by travelling along the edges, otherwise itis disconnected Ta reyaph G is-connecicd if given any vertices u ang ¥ it is possible to trav. Tee Potaiacent edacs of the graph] An example of connected smear graph with three componeié is shown in Fig 9.15; acmected ‘el from u to v along graph is shown in Fig. 9.18 and a h Gis said to be strongly connected, if for any pair of vertices u and v, there exists a path from sivvand vice versa “i ‘yz Y3 Ys Nw YZ . N53 V4 % V5 Ye ‘y 7 Fig. 9.18, ZOnnected Graph Fig. 9.19 Discga@ted Graph Gasiscomected graph is the union of two or more connected subgraphs each pair of which has no ‘etx in common, A disjoint subgraph H that is also called connected component of the graph G should ‘stsfy following conditions: © His subgraph of G. (i) is connected, " edges tha in H. ti) No connected subgraph of G has H as a subgraph and contains vertices or edges that are not in Wi ‘ 8 are (Vp, Voy Vor Vote LY “retanpe, the connected components of the graph shown in Fig, 9.18 are (Vj, V3. V5. Vols ae ROUNE LE MAIER L ARS. ——___ graph of 7 vertices v, 1 V5 2 ¥; i Fig. 9.20 Cycle C,, (n> 3) Whoo! The whecl.W,, isa graph obtained by adding an addlitional vertex tothe eete¢ isnew vertex to cach of the # vertices of C,, by new edges, 23204 conn LI 2 & Fig. 9.21, Wheels (Distance and Diameter In a connected graph G the distance between its vertices u and v is the k oe shortest path and is denoted by d(u, v)} In Fig. 9.22(a), d (1, 6) =2 and in Fig. 9.22(6), d (1, 5 : 7 ¥ 2 s 2 “7 oa, * My v; vt ; * 1 Vs Ns 5 YG ¥3 (0) (2) Fig. 9.22 Examples of Distance and Diameter fi or and is dn @ connected graph G the maximum distance between any two vertices is called a \ ; denoted by diam (G).\In Fig. 9.22(a) and Fig, 9.22(b)fthe diameter is, diam (G) = 3 and diam ( respectively. ad, where eS discounee' ig, 9.22(a)¥° id, (Gut Points and Bridges Vertex v in a connected graph G is called a cut point it GV G-v is the graph obtained from G by deleting the vertex v and all edges connectin 4 is the cut point _CHAPTER 9 GRAPH THEORY 269 of a connected graph_G is called a py, — APHIT ofl aicomenc ie eal Sealled 4 bridge or eu edge it Gee Io Leal an onneeted i id V3 such that there exist only if'its vertex se ma Be ee Wak Set V can be partitioned into two non-empty, a Nase one end vertex is in subset V, and the other “set V2 “ondition: Suppose partiti r insu yecessary Condition: Suppose partitioning of V into subsets V rool te awo arbitrary vertices such that v, @-V rand vy € V,, yand V, exists. Then, let v, and can exist between v; and v,, otherwise there No path can een Vitek Se there would be at least one edge whose one end nV and the other in V>, which is not Possible as V, and V. are disjoint. Hence, if a parti / yerteX fa js an unconnected graph ’ ae eee | exists 6 iS ond be a disconnected gra | in condition: Let G eS Sconces Braph and a vertex v, € G. Let V, be the set ofall vertices | ed by path to v1. Since G is disconnected, V, does not include all vertices of G. The remaining!| I be from a non-empty set Vo. Since no vertex in V, is joined to any vertex in V, by an edge, ic to partition vertax set V. Suficie! . that are join vertices will its possi reng5 Ifa graph (connected or disconnected) has exactly two vertices of odd degree, there must be a joining these two vertices. ey tet G be a graph with all even vertices, ie. all vertices with even degrees, except vertices ProM' x, odd degrees. If v, and vz are both connected with an edge, then these ave connected. “1 pv, and v, belong to different components then each one of these two components shall have one 1 yertex of odd degree, which is not possible. Hence, in graph G, v, and v, must belong to the same femponent and have a path between them, SH reo 96 A simple graph G with » vertices and k components cannot have more than AG op ie tpedaes. aa : : S? proof If n, represents the number of vertices in a component i, for 1 Ln 1) n=) which is possible only when & = 1. Hence, G is connected. | 5 Example 10. Find the connected components of the graph G shown in Fig. 9.24. Fig. 9.24 is ected component Solution (a) Take any vertex, say a, and find all vertices connected to it. So the set of conne is {a,d,e,h,c} ponent. cee in another compo! Next, select a vertex not included in this component and repeat the process to obtain ents is - : tof components Continue in this way until all components have been identified. In Fig, 9.24, another set 1b, f, 8}. Thus, the component of the. graph G are {a, d, e, h, c} and {b,f, 8}. : CHAPTER 9 GRAPH THEORY 271 ihe graph shown in Fig. 9.24, Docs G has any bridge age has any bride’? Example 11 Consider | Solution Since G— t6, A) and {di} are disconnected the bridges in G- «= connected components of a graph G (Y, Example 12. Find the cont (YB), where 4 sh na and G) B= Ha eed. (deo), (e, ay}, GY B= a, ph, therefore ede fe, hy and fd, hy are raph G (V, ) with given set of vertices and edges is This graph is contiected. Here the vertex pis connected G has only one set of components {b, ea, 6d} Solution (2) ThE shoven in Fig. 92 to all vertices. Th ya an empty set therefore all vertices are isolated and hence tai} and {e} are connected components of G, ao ¢-sobansrHs <> Bi ‘Subgraph ba () Subgraph G-es (c) Subgraph G-e of Fig. 9.31 ‘ AS cep 9.4.2 / Complement of a Subgraph on Complemos| Te complete ofa subgraph H(V’, E’) of a graph G(YV, E) is the subgraph H (V, E—E’). Thats, the complement of “subgraph H is obtained by removing edges of H from G. Figure 9.32(c) isthe complement of the subgraph in Fig. 9.32(b) with respect to the graph in Fig. subgraph G-e, obtained after deleting edge es = (v3, vs) is shown in Fig. 9.31(b). obtained after deleting the edge on (y v9) shown in Fig. 93169. (a). 1 e “ V2 y 2 V3 . * “ V2 ¥3 Ts fs 7 ae % fs Ne ler - “ x e | & a < ¥ 5 « —__,— oh = . 4 su : (@) Graph G (6) Subgraph H (c) Complement any Fig. 9.32 Complement of Subgraph 274 DISCRETE MATHEMATICS 9.4.3 \ Operations on Graphs ) In this section, we discuss some operations involving graphs. Union of graphs Let G, (V;, E,) and G, (V,, Ey) be two graphs. Then union of these eee ‘and is shown in Fig, 9.33, This graph is the union of graphs shown in ears ding Fig. 9.33(6). ie 923(q) 9 G, UG) = G;(V, U V2, E, UE). a tf e e 7 _- | e F ww S7 a . . ° age & e es es e ne F ¢ d os. e uw 7 Fig. 9.33(a) Gy Fig. 9.33(0) G, Fig. 9.33(¢) G, U inaaeton of graphs Let G,(V,, E,) and G,(V,, E,) be two graphs. Then 5 “ac ‘itersection of these graphs is defined as: —t, G, AG, = G; (Vy AV, E, OE) . The intersection of graphs G, and G, shown in Fig. 9.33(a) and Fig. 9.33(6) 7 is given Fig. 9.34. 7 J Complement The complement G of graph G is the graph with se Ween See fo ay os CG 34 G, 9G, G with two adjacent vertices u and’v.that are not adjacent i :xample of ‘complement of G is shown in Fig, 9.35(a) and Fig. 9.35(b). y 1 a1 v2 v5 v2 3 v4 V6 “4 % Ys V5 (a) Graph G (8) Complement G = Fig. 9.35 Example of Complement Graph a CHAPTER 9 GHAPHL THEORY 276 vow Repent ies oF graphs ave ivcusel Here whieh re Hrequenty wed in yap ull goat) i) i oY pis called nll raph (aso called totaly disgomnected yap i brevery vertex isan tole vertex In Fg, 9.36, nul is shown, " ye raph, Mathematically, a null graph and Ved ) “A mull graph is also called ve dige set is emply, ic. E is one who oN, 9.36 Pxample of Null Graph ted graph where for all vertices vp. vj © V,v,% vp there exists an na complete graph every vertex is connected to every other vertex, ery compote SH] iD ‘A complete graph is 100 In other words denoted by K,, and has (1/2) n(n ~ 1) edges. A complete a K,, form = 1,2, 9.37) show undirected complete graph K,, x a Nw “oY % — Vy V3 Ya < } (Be @k— - 9.37(a) 0 . | (be WK OB _/¥ig. 9.87 Examples of Undirected Complete Graph T 1 ow) =2 hog (V9) ~ 2, dia (vy 4 Rogular Graph [1 ) Ww) L) = , dg vy [arp in which every vertex ns the same dere called regu graph every vertex ts degree en graph is called a regular graph of degree i Every null graph is regular of degree zero and «complete graph K,, is regular of degree m ~ 1. Note that ifa graph G has n vertices-and is regular of degree 1, then it hiss (1/2) rn ed I in regular undirected graph, every vertex has the same degree, say &, then graph is called k-regular (onmtnentary Graph (j v) Tet G be a loop-free undirected graph with m vertices. The complement of G denoted as G is the subgraph of K, consisting of the n vertices in Gand all edges that are not in G. That is, if G=K,, then G is a graph In other words, G is the graph which has the same number of ertices consisting of n vertices and no edg vertices as in G with two of them are-Connected if and only if they are not connected in G. That is, v which are adjacent in G are not adjacent in G and vice versa. Figure 9.38 shows an undirected with 5 vertices. Its complement is shown in Fig. V2 is isolated, 9,38(b) where vertex MESOLEGEE Discrete MATHEMATICS vt v> — x % % us t Fig. 9.88¢a1 ‘ %, coe) Gaypird Min. 9.3806) Compley Example 18 (a) Draw the connected regi ular graphs of degree 0, | ) Draw two 3-regular grap ; and 2, s with six Solution (a) The required connected regul lar graphs of degree 0, 1 respect and2 areshoun in.ig.0,39(a), (andy, (b) and, fer AOU (0) O-repulr (b) I-regular (0) 2-regulae Fig. 9.39 Examples of Regular Graph (6) The required 3-regular graphs with six vertices are shown in Fig. 9.40(a) and Fig. 9.40(6). W & Fig. 9.40 Examples of Regular Graph [weiss Graphiy) A loop-free graph G is said to be a weighted graph if a positive real-number.called the weight is assigned {0 each of its edge ¢ = (vp vj). Ruch a weight is denoted by wt (e) or wt (vp vj). If yp vj € V but Yn ¥€ E, then wt (vy vy) = 09, — CHAPTER 9 GRAPH THE ar| — : For each = (¥p Np @ Fs the weight may represent (the ten road f anor eee 0n this road frm ¥ 1X OF GHD the cost of tact fem rer ne cg tarda : om v, to wv, on this road Bipartite eran OF HINe raph G is ealled bipartite graph iF it is possible to pa FX loop-free graph G is led bip " possible to partition the vertex set V ji . i ich that every edge (vp ¥)) connects a vertex in V, anda verre an oes 1 and a vertex in Vp, ie. there sino edge F, and V> of verte e set V, or V3. In other words, a graph Gi i 7 band every edge of 7 + a graph G is called bipartite graph when UV and Vp and every edge of G is of the form fv), vj} with v, € V, and V je Va joining Qvo Vel nd Ky, are shown in Fig, 9.41(a) and Fig, 9.41(b), respectively. y VeWOVg vy V2 a % IY MAVa= Meee epee ae bra \, OKaa 7) Fig. 9.41. Examples of Bipartite Graphs Vevyu vz and bipartite graphs Ky aM Gireach vertex in V, is joined with every vertex in V,, i.e. there is an edge between each pair of vertices in V, and V>, then such a bipartite graph is called complete bipartite graph. Now if number Srvertives in V, are m and number vertices in V, are, then such a graph is denoted by Ky, A complete bipartite graph K,,, , has m+n vertices and mn wines fi 9.41 is an example of complete bipartite graph. ‘w ‘2 v1 v2 ¥3 \\ | | | v: V4 Vs v4 Vs Vo 3 (@) Koy, Vi Va} Vo = {¥3y Var Vs} (b) Ky3i Vi = {¥ps Y2r he. Fig. 9.42 Examples of Complete Bipartite oat | nverticesare7/4. Example 17 Show that the maximum number of edges ina complete bipartite graph with ex set V of G. Since iin Let Gy, E) be a bipartite graph and let V, and V2 be partition of the vert tee, THUS tec omplete bipartite graph, each vertex in V, is joined to each vertex in V, by exactly one edge. Tihs ire myn, edges in G, where n, +n. =n, But the maximum value of yz subject to" Nn mid, is Hence, the maximum number of edges in G are 17/4. w vo “do 10 AS thoes tenn *2 Which connect vertices u and yo" Paths Py and pt exigt d As there is no path in P, A P, coi nnecting vertices u and 2 Connecting u and v are edge- disjoint, Thus, uni - inion of circuit in P, U P, as shown in Fig, 9.43, eae P. Fig. 9.43 [ravrate Multigraph Wii) ‘ i A multigraph G is said to be traversable if \y it can be drawn without any break in the « curve and without repeating any edge. That” aa. 2 is. if there is a path which includes all Yt vertices and uses each edge exactly once. eT ee Such a path must be a trial (since no edge ’ date is used twiceLand it will be called a Le % e traversable trial. A traversable multigraph V3 fs obviously miist be connected and have either zero or two vertices of odd deere aL Ca Figure 9.44(6) shows a ee Fig. 9.44 Examples of Traversable Multigraph of the multigraph in Fig. 9.4(a). Remark To prove a graph to be traversable, find the degree of each vertex and the determine whether all the vertices are of even degree or exactly two are of odd degree. If either condition is met, the graph i waversable, Example 19 (a) Draw the complete graphs K, and (b) Find the number of edges in the graphs K,, andKj, Solution (a) First draw given number of vertices and then draw edges from each vertex 10 every vertex. The graphs for Ks and K, are shown in Fig. 9.45(a) and Fig. 9.45(6). rer rrr icone SBS Oo oye Fig. 9.45 ir of vertices determines an edge. Thus, general formula for determining number of edges (2) Since cae Poin eee 'C, =n (n— 1), because there are "C. f sel Sin ete graph K, is "C, = 1 (= 1/2, boca ¢ are "C, ways of selecting two vertices out of in oa dence, in Ky, m = 12 * 11/2 = 66 edges and in Kj,, m= 15 x 14/2 = 105 edges | nve Example, b P d Es d @ \ 3 Find which of the graphs shown in Fig. 9.46 are traversable. a a QE e if aii « on” . \ © x Fig. 9.46 Solution (a) Graph shown in Fig. 9.46(a) is traversable, as two of vertices a and f are of odd degrec vertices. . (6) Graph shown in Fig. 9.45(8) is traversable, as two of vertices b and c ate of odd degree vertices. (©) Graph shown in Fig. 9.45(c) is not traversable, as four vertices a, b, c, and d are of odd degree. Example 21. Find the traversable trail for the graph G(V, E), where G = {a, b, c,d} and V = {(a, G4), (b,c), (bd), (c, d)}. : a b (a)_— (b) a Fig. 9.47 oe ae. we 280 DISCRETE MATHEMATICS ~ Solution ‘The graph G (V, E) is shown in Fig. 9.47. The traversable trial shoutg dearee and end at the other vertices of odd degree. In Fig, 9.47%(a), v Fig, 9.47(0) gives one such solution ase = fe, a de by cy aie | Example 22 Construct a graph which is both regular and bipartite Solution The bipartite ae h Vertex is connected to nr other vertices and hence, its depee ism. An example Dr eraph Ky is shown in Fig. OAS, whieh is J-requilar this graph we « delete m disjoint edges and cach time obtain a regular graph of one degree y be disconnected, but in any case their connceted | bepin fron Hd ate odd Vertigg 4 depree yon Md Yettig HK, 4 8 regular of degree mr because less. These graphs 1: components have the desired properties. Fig. 9.45 Euler Graph : : : A aeaph is called Evlerian or Euler graph it it contains an Eulerian circuit (or line). A Eulerian j connected. alwa} Eulerian trial A trial contai Fulercieenit A closed trial (ie. a citcuit) containing all the edges of the graph is called an Eulerian er (online). | Iustrations: The graphs shown in Fig. 9.49(a) and Fi 1, The graph given in Fig. 9.49(a) is a Eulerian graph because it contains the Eulerian circuits: {v 4 Vge Var Vow Ya} and {Vy Var Van Vay Vox Yor Vie Yas sr Vide ing all the edges of the graph is called an Eulerian trial, .49(b) are Eulerian graphs as Yop vy Vp Ve V3 +The graph given in Fig, 9.49(#) is also a Euler graph because it contains Buleriam circuits: {vy Vg Ve Vo Yih and {ps Yop Yap Var Vio Yor Mt} v1 vs vy Y% %s vy yy vs Yo %9 V4 (6) i o = Fig.9.49 S. 9.6 ISOMORPHIC GRAPHS \i\> Let G,(V,, E)) and Gp(Vp, E,) be two undirected graphs. A function f: V, —> V2 is called a graph isomorphism if (i) fis one-to-one and onto, ive, there exist a one-to-one correspondence between their vertices as well as edges (both the graphs have equal number of vertices and edges, however, vertices My have different levels) and (ii) for all u,v € V,, {u,v} € E, ifand only if {/(w),/(¥)} € Ex. Ifsuch a fun exists, then graphs G, and G, are called isomorphic graphs. Graphs shown in Fig, 9.50(a) and Fig. 9.50(6) are examples of isomorphic graphs CHAPTER 9 GRAPH THEORY 281 | Fig. 9.80 Examples af fsomorphic Graphe remark By definition two isomomhie graphs must have {a equal number of vertices and edges equal number of vertices with same degree (ii tt should be possible to start at any vertex in two graphs and find a circuit that inet edge of the graph, Example 28 Show that the graphs shown in Fig, 9.51(a) and Fig. 9.51(4) are isomorphic w that two graphs are Solution To show a : namomphic, WE can arrange vertices from both grants having same degrees in decreasing onder : ordgrees. Hf both graphs contain vertices having p came degree, then they are isomorphic, otherwise - b a vy . () fot Note that no vertex is left out in any of the traphs which is not matching in terms of degree seith the vertex in other graph, In Fig. 9.51(a) and Fig. 9.51(8), pairs of vertices in decreasing order @ of their degrees are follows: Fig 351 Degree 3: deg (c) = deg (v2); deg (a) = deg (v,); deg (d) = deg (v,) Degree 2: deg (b) = deg (v3) Degree 1: deg (e) = deg (v4) Since both the graphs contain vertices having same degrees, therefore, they are isomorphic. Example 24 Show that the graphs shown in Fig. 9.52(a) and Fig, 9.52(b) are not isomorphic. b © v5 - vy vy a d m2) Ms e (a) (0) Fig, 9.52 Solution The Such vertex, | sraph in Fig, 9.52(a) vertex b has degree 4, whereas graph in Fig. 9.52(b) there is no Hence, graphs are not isomorphic, a ‘ DISCRETE MATHEMATICS HOMEOMORPHIG GRAPHS 7 }>° Let G be a loop-free undirected graph. An elementary subdivision of G results is removed from G and then the edges {u, w} and {w, v} are added to Gee. un A loop-free undirected graph G, (Vj), E,) is said to be homeomo: graph G, (V,, E,) if they are isomorphic opif they hen an edge es ie, where w ¢ 7 = tu yy hie to another | e obtaine a be obtained from the same loopefive Free uy ni tne by a sequence of elementary subdivi ee ee a Fig. 9.53 Example of Homeomorphic Graphs The graphs in Fig. 9.53(b) and Fig. 9.53(c) are homeomorphic, since each can be obtai fica! ‘5 bt in Fig. 9.53(a) by adding appropriate vertices. ee Example 25 Consider a finite graph as shown in Fig. 9.54. Show that it can be homeomorphic to one of its subgraphs. Solution Deleting one or both of the vertices of degree 1 from G as shown in Fig. 9.54 yields a subgraph which is homeomorphic to G itself. Hence, a finite graph can be homeomorphic to one of its subgraphs other than itself. Example 26 Verify whether two.graphs in Fig. 9.55-are isomorphic. nee Solution Each of the two graphs shown in Fig. 9.55 has six vertices and nine edges. In Fig. 9.55(b), if we start at vertex u, then we find a circuit u > w >v 9y Sw zy 3x5 v — u, But it is not possible to find a circuit in Fig. 9.55(a) where the only trails that includes each edge start at either & or e and then terminate at e or b, respectively. Hence, two graphs are not isomorphic. . 5 SA 7S a8 y z (@) @) Fig. 9.55 CHAPTER 9 GRAPH THEORY 283 ge (REPRESENTATION OF GRAPHS IN COMPUTER MEMORY —| are geomettic figures, their represe ough graphs are 6 ha atrix (or vertex-vertex adja 1. Adjacency ion in computer memory rei presenti | P Wory requires lot of storage ix) ix) eney m Incidence matrix (or vertescedge incite - yy lists 3 Adie ; Be ses Hr reset : jest two methods. However, irrespective of the ways a graph is Jrapter, we shall discuss only in this € memory of the computer, its formal definition as a collection of vertices and edges aintained inthe mem {a collection of pair of ve 9.8.1 Representation of Undirected Graph | ca siasener matrix The adjacency matrix also called sequential representation method is suited to raph G with 1 vertices and m edges is said to be dense when representation of ‘ome constant &, storage space in computer memory, representation, stores the graph G consists of n vertices and no parallel edges, in vy, as an iar matrix A = [a,] defined as: ices) is used as input to the computer. represent a graph G. A gt it re res An, for rAdjacency matri the order Vj» Yor i { if vertex v, is adjacent to vertex v; i.e., there is an edge between yj and y, i 0 otherwise. 16 specifies 55 matrix representation for the graph consists of 5 vertices, shown in Figure, 9-5 Vay V3p Vay V5 and each edge (v;, v,) of G is represented twice Fig. 9.57{(Note that vertices are ordered v,, by a, = Pand a= 1. V2 Vy a Ya Vs Va ¥5 oa) “1 ors oo 1 0 1 ‘ 0 aenuo he oee re@ereo V3 *s Fig. 9.56 Adjacency Matrix Fig. 9.57 Graph Example Since adjacency matrix representation is based on ordering of vertices in a graph, therefore, for 2 graph with n vertices, we may construct as many as n! different adjacency matrices because there arc n! different ordering of n vertices) A number of other important results about the adjacency matrix are 3 follow: () The adjacency matrix A is symmetric, i.c. ay = Fi for all i and j. (ii) For a loop-free graph, the clement ay = 1, ij represents degree of a vertex, The entries alon; the principal diagonal are all 0’s. But, a self-loop at the vertex correspondilg to 4, DISCRETE MATHEMATICS Yioa graph G is connected graph if and only if the matrix BHA+At4... 4A"! has no zero entries off the main diagonal, where A is the adjceney matrix of ¢ of G with y Vetteg * v v (iv) The adjacent fvatrix has 1* een ency matrices are useful for deten ‘eraphs. For example, it is easy to show that there is a path of length r (ie. Vertex 1 t0 v, if and only if A’ = 1, where A” is the rth matrix product, Jo ‘The number of non-zero clements in the matrix is equal to the sum of degrees ofall vei the graph ices of Example 27. Use adjacency matrix to represent the graph shown in Fig. 9.58(a), (6), (c) and (a Folution (a) We order the vertices in Fig. 9.58(a) as vj, Vz. Vj. Vg and Vs. The adjacency marr representing this graph will be the square matrix of order 5 as given below: x i ae ee Ore le Ole 0 wile 0 0 el, 0 vila 0405 la. 0) c vilO; tel. 40,1 wells 0 Om nl <0, -" v2 y | * . os « . v3 7 ® Gein 8 vd wise REL) —<—S> © oy Fig. 9.58 CHAPTER 9 GRAPH THEORY 285 9.SH() as ¥ We onter the vertices in Fig Yue Ya and vy ph is given below the adjacency matrix representing a the era : | 2) Weoonler the vertices in Pig, 9.58(e) a8 vy, ¥ giaph is given below yand v4. The adjacency matrix representing this vy OY) Vy Vy a We onder the vertices in Fig. 9.58(d) as vy, v3, vy and vy, The adjacency matrix representing this graph is as follow vene YY, 4 eu % vill 0 Oo A=v,]0 0 1 0 v3]0 1 0 1 Val 1s5.0 (0.01 Solution Since the given adjacency matrix is of order four, the graph G ) has four vertices v), vz, v3 and vy. Draw an edge v; tov, where 3 (b) Incidence matrix An incidence matrix stores the graph G consists of n vertices and m edges as an ™ matrix M ji 1, The required graph is shown in Fig. 9. 5) Fig. 959-7 m,] defined as: 1 if'vertex v, is incident on edge e, m, = ; i 0 otherwise is cqult matrix has a row for every vertex and a column for every edge. The non-zero elements inthe matrix « : ‘nul to the sum of degrees of all vertices of the graph Pe DISCRETE MATHEMATICS Figure 9.60 specifies 5 * 8 matrix representation for the graph consiss of vertcg S and in Fig. 9.61 Bedaes, > hoy ey &y 4 es % OF " vf i 1 Pots 2 oe oe cet 0-0 | 0 0 0° 0 Mev} 0 Of 0 0 v,| 0 0 . 2 jee | ee 2 eee ea 9,60 Incidence Matrix \we make the following observations about incident matrix M of graph G: ) Each column contains exactly two unit elements. (i) A row with all zero elements corresponds to an isolated vertex. iii) A row with a single unit element corresponds to a pendent vertex. (i) The number of unit elements in row i represents the degree of the vertex vy, (0) If graph G is connected with m vertices, then rank of incidence matrix M o. Example 29. Use adjacency matrix and incidence matrix to ee the graph eae Fig. 9.62. Lavoe Solution We order the vertices in Fig. 9.62 as v,, v2, v3 and y Vg the adjacency matrix representing the graph is given below: « - ‘Vy V2 V3 Va 4) ep &3 C4 C5 6 7 &% e4| vf2 1.0 vfl 1111000 A=v]1 01 0], M=v{0 010 0 1 0 1) we = 2 sa valid OL vJ00010110 le vall 1 1 0 vjo0001011 % Fig. 9.62 Adjacency matrix Incidence matrix 9.8.2 | Representation of muttigranh| When graph G is a multigraph, then a, denote the number of edges (Vj, D a iges (V), used to represent multigraphs. Adjacency matrix. . Fora multigraph G consists of n vertices, an n n adjacency matrix A = [ay] is defined as vj). Thus, only adjacency matrix 'm — if there are one or more edges between ay = vertex v, and v, ; m= number of edges 0 otherwise “The following adjacency 4% 4 matrix representation fora multigraph consists of4 vertices is shown in Fig. 96% CHAPTER 9 GRAPH THEORY vy vy MMe vf Sal oe) ead vfo lo oO AaljareSy Mara ec ample 80 Determine the number of loops and multiple edges in a multigraph G from its adj jaceney matrix raw the graph Gand check your Solution Since adjacency matrix A trix of order 4, graph G has four vertices Vy. V3. Vy» Var The diagonal of A is indicating the ve foops because’ these entries indicate the number of edg tesminating at the same vertex. Thus, there are three loops: one at vertex v, and two at vertex V2 as shown in Fig. 9.64. To find the number of multiple edges, add the number of entries greater than 1 below the main diagonal and add the number of entries greater than 1 along the sain diagonal. Main diagonal is also included since multiple loops are also multiple edges. Entries above the main diagonal are not considered because matrix is symmetric. Thus, in Fig. 9.64, there are seven multiple edges,2 edges from v, to v,;3 edges from v, to v3; and 2 loops at V2. A %5 %s 9.64 Multigraph 9.8.3 {Renresentaton of Directed Graph | ‘A directed graph, also called a digraph is denoted by drawing a diagram rather than explicitly listing its vertices and ete) yy OF) Pte] ‘2 ne 00 1 0 1000 oo 1 1 Op alk: 01: 0 7 Adjaci sey Sax) {) ——$——$ 2 {EMATICS = j consists of 1 vertices, an” 1 adjacency . , ix For a directed graph G con ney matrix Faajacency matrix Fors Nay, ning at vertex v, and ending at y, It fy Yo. otherwise : [i onzeroctements in the matin i equal-torte number of edgesfin the digraph ne non-7er0 ele A she following adjacency $ * $ matrix representation for the digraph is given in Fig. 9,65, sence maarix For a directed graph G consists of 7 vertices and m edges, an 11 m incide incidence matrix grap incidence ty, 3H = [mp] is defined as " 1 ify, is initial vertex of edge ¢, vertex of edge ¢, My, =4 71 ity, isi 0 ifv, not incident on edge ¢, ‘The non-zero elements in the matrix is equal 10 the number of edges in the digraph. The following 5 * 5 incidence matrix representation for the digraph is given in Pig-9.66 in eo) ey ccd) 5) oes -1 1 0-1 0 0 0 10 10 1 0 0 0-1-1 0 0 0 O70 0 de, O--1 0 (0) 015022 1c Incidence Matrix or vy 6 Ns ( Fig. 9.66 Digraph Example 9.9 EULERIAN AND HAMILTONIAN GRAPHS = —I—-AcY~A a aN | 314, _DISCRETE MATHEMATICS 102 DEFINITIONS AND PROPERTIES OF TREES [Lec (vB) bea loop-free undirected graph, The graph G is elle tre i itis connected and without ¢ i is not a tre : cl [oops). In Fig. 10.1, the graph G, is a tree, but graph G, is not a tree because it contains the tay {¥or Vids (Vp Vahs {Vg Va} {2 Vg}. Trees are also defined as a non-empty finite set of clemenis alle nodes (or vertices) Vy partitioned into three disjoint subsets. The st subset contains a single elem called the root of the tree.\The other two subsets agp called /efi and right subirees (oF branches) of Hl original tree. Any of thes subtrees can be empty. [The relationship among elements of the origina, i satisfy the following properties: (i There exist at least two vertices with degree 1. (ii) Every pair of vertices is connected by a unique path. (ii) There exists one vertex vo (often called the roof of the tree) with the property that there is unigy path from Vg to every other vertex in the tree but no path from vg to itself. (i) Each vertex other than the root has exactly one predecessor. () A tree with 7 vertices has 2-1 edges. 6 % Vs Fig. ie Fig. 10.106) “GraphG,— Not a Tree The tree in Fig. 10.1(a) consists of eight nodes with v, its right subtree is rooted at v,. This is indicated by the two branches emanatin and to v, on the right. The absence of a branch indicates an em structure that is not a tree. o 88 its root. Its left subtree is rooted at v, and g from vo to v, on the lef ipty subtree. Fig. 10.1(6) illustrates « 10.2.1 Rooted Trees Tooted tree is a tree with a designated vertex vg called its root and satisfies following properties: () There is no cycle in the tree’ (ii) The root of the tree is unique. (iti) Each vertex in the tree other than its root vertex, has indeg (v= | and root vertex has indeg (v,)=0- Figure 10.2 is an example of a rooted tree “ Vertex vq is the root of the tree that appears on tht top of the tree (i.e. the tree grows downward: _— f CHAPTER 19 RES EES 315 | < jges in a rooted tree define The IEE cessor (oF parent-child) Neeser" 2, verter vy is the Ma Level d preeery ip. In Fig. 10.2. VeHIES So relation of vy and vy, These jocess0F 8 wyertices Vy> Hed Jew? t verti Hf © anal Vp is sometimes = a ppt these tevel 1 veitices auied he PONTE. are callest offspring sr while vertices V5, Ar vertex Vy jitdren of vertex vy. The cs. while Vp ves are tre at re called oN eang the same parent are also ce Hv of each other Each vertex at pene niering it, but fave edge or edges leaving it, The edges leaving a vertex at fevel 1 are d rd and terminate at various vertices such AS 84 Vas Vays Yap Yh and v9, which are said to be cand ar de called the parent of the two Offprng va, and Yay This process contins 7 2 ¢ are required to complete the tree. a 5 ts of the vertex itself, all its children together with descendents yy and Vs ag.many levels for : Maye descendent of a vertex ¥; Cont Saoxe children) In Fiz 10.2, for example, vertices Vy2}- Vp1s ¥22 are considered descendent of v, and v, be ces are descendents of the root vertex. 2 and Yo qn tree all Vo : gee no offspring are called the leaves of the tree, i.e. Jeaves of the tree are Fite verons of the t VA directed path from any vertex to a leaf is ealled a branch. Nertices ¥,y- ¥ 12 tne werices of degree on . reaverin Fig. 10.2. The paths (Yo. Yj. Vit» Vira» (or Mis Ys “igh (Yor Yo Yaa: Yan og and gq) 1p EE P 4 1 oN es) The path length of a vertex in a rooted tree is the number of edges in the path from root cic. are ba to the vertex. eve 4. which has no children, ic. outdeg (v) = 0, ae called external (leaf or terminal) vertices = branch (non-terminal) nodes} A vertex nm is called an ancestor of vertex n, (and n, is a js either the pafent of nm, or the parent of some ancestor of 1. For example, in and Vga, is the descendant of v2, but vj, is neither an ancestor nor 2 athe ( > For the‘fee shown in Fig. 10.2, this ordering yields. 0 LLL pel 2.2.1 1 12 | 2. 3 3.2 pee wi 113 32 "dering is called lexicographic or dictionary orde bs ogee 40.2.2 (Height of the Tree ‘The soot of Mie tree has level 0, and thé level of any other vertex in the tree is one more than the leve parent) In Fig. 10.2, vertices V; . Vy. 94s Va9s Vay and V3 are at level 2 and vertices ¥, 11,4 13,¥415 and y oF ity a tree is the. maximum level of any leaf in the tree. This equals the fraehe Ih of at level 3/The depth (or helwht ol The tree in Fig. 10.2 is of eight cy the longest path from the root of any lea Theor 101 Prove that there is unique path between each pair of vertices in a tree T(V, By Proof Since wee T (Vs E) is connected, there exists at least one path between each pair of distinct ven in T. Suppose. there exist two distinct paths between a pair of vertices w and v in T, then some of the pa from these paths will form a cycle. Since a tree has no cycle, therefore, T cannot be a tree, les Theorem 10.2. If ina graph G, there is one and only one path between every pair of vertices, G isa ty Proof Ina connected graph G, there is only one path between every pair of vertices of G. Since hy, only one path between every pair of it cannot have any cycle (as existence of cycle requires two of morg path between a pair of vertices). Hence, G is @ connected acyclic graph and is, hence itis, a tree. Theorem 10.3 A tree T(V, E) with n vertices has » — 1 edges. all prove this theorem by mathematical induction on the number of vertices, sin T, k (2 2), where k is some positive integer. To prove that the result is also true for » = k + 1, suppose T has k + 1 vertices. If we remove an edge with end points u and y from T, then we are left with two sub-trees T, (V,, E,) and T, (V2, E,) such that [V| = |V,| + Vol and IE] = [E,| + [Eq\ + 1. Obviously T, and 7, are connected with no cycles, and having vertices less thanm ie. [VjI- CHAPTER 19. TREES 317 onnected graph with 1 vertices and (yy | 1) edges is tre Any ¢ 10.5 er af edges required for a praph with 1 ye en e minimum number of edge 1! yf Since 4 +a connected graph with 1 vertice [proof Sires eretore a egnnected tives to be §) edges eg connected (or acyclic) ‘annot have a cycle and nid Gr - raph 18 graph G is a (ree, J connected graph (a connected graph with » verti mal 6 1 a tree. vias A minimally connected graph is a tree, Thus ir ; all also keep C and n— 1 edges) @ graph is not min @ as connected, but G will not 06 A connected graph G is a tree if any only if i fet an exactly one circuit, Armin eat canal an edge ¢ from C ‘Thus the theorem mally connected, be a tree adding an edge between any two vertices of Theorem G creates Le pemark The following are S different but equivalent detinit a n vertices 1S called a tree if nitions of a tre . fo Gis connected, and no eveles. {oy Gis connected with [VI = Th * 1 (8) G contains no eyetes with [VI = BLY Y (a) Gis connec 1 be disconnected into two sub-graphs that graphs that are trees by deleti ting any ed ge from ¢ i) There is exae ath between each pair of vertices in G. Example 1 Consider th The vertices Vy Yo Ys * Solution The path length in _ is obtained by listing # + (Ve Yy) path length is one, 1» Vg) path length is two. “ vye Vs Path Tength is three. Voy Via» Vig)» Path length is four. Yo . A loop-tree undireet cted gray Dh wit, ed and tly one 1 he rooted tree shown in Fig. 1 2. 10.3, Identify the pa a y the path length frorw its root to each “ach of the rooted tree as shown in Fig. 10. he vertices betwee! st i it tween these {wo vertices including the vertex itself as follox’ s follows from its root to each of the vertices y, and Vy From Vg 1 ¥y From Vo t0 Ve? (Wor Fram Vg t0 Vg 3 (or ¥ From Vg 10. V3! (or Yr The vertices Vs, Vg and V, are the children 9 1 vertes y is v, and the children of v, ar » PE Vy cand y «hx Hsia 1nd hemes SMES imme {d) The parent of V3 ely follow y Us the only sibling ary 10.3 BINARY TREES ee T is calleg an mary rooted tree wher {Footed tree n a ‘when each inte A ret) cin forall Tin particular if each internaLverten utarmenn ete | Aer rad 2-ary binarberee, ic. order (Vv) =0, | or2, Figure 10.4 a Hee basal most tis 0 reg RS : an examp! b a rooted tree having Tollowing propertion tt! tree is always odd, say p in a binary tree is of degree 1, then p i “p mt mo Mm children ice children, then ay en hen ue » binary tree is * number of vertices ina binar ay Th verti 1 Ifthe number of vertice Vis the number of vertices Wi of degree 4 wee consisting of no node (null {ree oF empty tHee) is also a binary te : ¢ applications of binary tree as a useful data structure in compte 5 science ne of th $0 as a qed to take a two-way decision at cach point in a process. For example, to find all duplic arises when we 4 a icates in a list of a we compare each number with all those that precede it. The la ees wan be reduced by using a binary trees n° MtB® numberof comparisons nesded Ifa tree T contains unique vertex called its root, then the remaining vertices of T form an ordered pair of disjoint binary trees T, and T,. However, if T does not contain root, then the two trees T, and T, are called, respectively, the /eft sub-tree and right ‘ubetree of the root. In other words, the left and right Ghd of some vertex (node) is called left and right sub-tree of that vertex, respectively. But if T, is non- empty, then its roots is called the /eft successor of the root vertex. Similarly, if T, is non-empty, then its root is called the right successor of the root vertex. Remarks { 1. A vertex of degree one is also called pendent Vertex. 2. Ifevery non-leaf vertex in a binary tree has non- Fig, 10.4 Example of a Binary Tree empty left and right subetrees, the tree is termed asa strictly binary tree. Theorem 10.11 The number-6f vertices in a binary tree is always odd. Proof In any tree there is only one vertex of even (= 2) degree and the remaining ( ze of Odd dere. Since number of vertices with odd degree in a tree has to be even, therefore m1 '5 8 Provided m is odd, n— 1) vertices are of Theo Jere n is the number § att 1042 The number of pendant vertices in a tree is equal to p= (n * 1), whew nS Ge A re na binary tree OOF Sin : Will be p me total number of vertices in the given binary tree i = So number of vertices with degree 2 is one, so number of vertices ne PI. Th ‘us number of degrees of all vertices are en, er of pendant vertices srefore number of pendant ve are n, therefore num Pp an Fe 5 with degree 3 tinber oF endian: week eH OF pendant vertices 10.5.1) Forest | A.graph with no ace “ ino evel, where each node (verte) fas ome Ora aut fost in which ony a snge nde elle the roo vertices from of disjoiyt trees obtained by deleting the root S from a given wee] Fie 10.5(a) gives an example of @ Forest vue tess than the varno predecessors is called a forest. A tee has no predecessors. Any FOF cons | the corresponding, edges connecting tp, a % eX 4 ‘y y Ng ‘g Vo (6) Fig. 10.5 Example of a Forest To convert the given forest as shown in Fig, 10.5(a) into a binary tree, the root node of it is the x second tree becomes the right child of the node of the first tree from left and the root node of the node in binary tee and the root node of the third tree becomes the right child of the right child in binay (@) 10.5(0) wee. The process is repeated for each level till complete binary tree is obtained as shown in Fi Example 3 Consider the binary tree shown in Fig. 10.4. i) Find the level of each vertex. (b) Find the height or depth of each vertex. (c) List the children of each vertex. lie 1eit suLLESSLL UI vy 1) OUL TINT successor of v, in T, rooted tees). Vertex V3 18 2m 2 in T, eneral tree and a binary tree. Distinguish between a g Example 5 The general tree is different than a binary tree due to following reasons: Solution The g i.e. it may not contain any node), but a general tree is non- inary tree may be an empty tree (i.e. it (@ A binary ee ild, then it is distinguished as a left child or right, but no i if a vertex (nodes) has a child, then it is distinguished | ae aaa exists in a general tree, for example, trees T, and T, in Fig. 10.6 are different when such di these are considered as binary trees, otherwise these two are same general trees. ese a 62 = 6/2 =3 #4344357 )~+5* 624799) (2) 56+ 254% 244 S64 96 6 TRAVERSING BINARY TREES al Sometimes, it is desirable repress by the tee Tay eet Pf some compan apne to the application beg 7 SF example, at each vertex of a tree that represents an alg HC expression, We nay desire to perform a computation indicated by the operator at that vertex. The process of visiting then performing some computation at even vertex of a tree is called searching or performing a tee sayy This process is also called walking or traversing the tr A psirese cach vertex of a binary tree has exactly A labstied with different numbers from 1 te not with English alphabet A to Z. Such a labelled tree ig sometimes called Positional binary tree\ The root of the tree is not labelled, Since i is not an offspring of any vertex. The positions of the offspring is also indicated by the direction of the edges as shown in Fig. 10.11, Since each vertex of a positional binary tree has two potential offspring, therefore, these oBSpring will be denoted as vy (left offspring) and vg (right offgpuing) \ The following are three standard recursive methods (or aledrithis) for searching (traversing) a positional binary tree T with root v 1. Preorder search 2. Inorder search 3,_Postorder search 12 each of its nodes (vertices) once in «y and Sach of these childre dren (offspring). ms Fig. 10.11 Positional Tree (ee. Preorder Search a of preorder search (also known as depth-first order search) algorithm are as follows: (a) First visit the root v of the tree. (b) If v, exists, then search the left sub-tree T, of T in preorder. (c) If vp exists, then search the right sub-tree Tp of T in preorder. CHAPTER 10 TREES nal bina For example, let a pos TY tree T be with t I ices B, D, EH, 0 h root vertex A. The left subiree consists eine ei . iaht sub-tree Ty consists of vertices C.F, G, K and L, L ly preorder search on leit suing T, i ist, we apply Pre0 : 1 een bated 8 1. For’ this, “wo: atit pS seare| “i by first visiting its roots vertex B and thos Yertices DH, E, Vand J in thig omen : Li f a enrel é Silly, applying preorder search of Fight substree ‘T 1 ik Mumbered as 7. -aeittag 18 vertex C . first visiting its root vertex C and 4 KG and L in this hen vertices gat bY : Ne preorder search of Tp, Te result of compete preorder search oF the given ty i order. the string A BDH ELICRK GL. A (0) Search the left sub-tree T, in inorder, (6) Misi the root of the tree, (©) Search the right sub-tree Tp, in inorder. The inorder search of T as shown in Fig. 10.12 starts with the search of left sub-tree T,. For this, we fs seach root vertex A.and then right subtree Tr, The inorder search of left sub-tree T, starts from its na ees B numbered as, i Grly Prins the level of the ver Ti and search vertices | ofl subtree Wee T, tex, therefore, the order of search is HD. , E and J in this order, ing (Ne Misi the root vertex A. This yie Sarting from Sub-tree 8, 9 and 7 and then sear i result of complete inorder search of the gi Nes low, we proceed to search’ sub- which gives the string IEJ. After completing search lds the string HDBIEJA. Proceed to search right sub- irch sub-tree 10 and 11. This gives the string FKCGL. iven tree is the string: HDBIEJAFKCG a () General Tree : (1) inary Tree ig 10.10 Comespondence between General Tree and binary 1 Solution Applying the Procedure for ¢ onvertin : r NB general tree int a binary tre eae Beneral tree into a binary tree we obtain 4 general tree T is usually maint Oe (or DOWN) and SIBL. Each node v of T wi ined in the mem (or HORZ), and ill correspond to a tox ory Of the computer by m cans of three parallel arrays 4 pointer variable ROO: T as Follows: eation K such that 1. INFO [’] contains the data at node y. 2 CHILD [K} contains the location of the frst Child of v. The condition CHILD [&"]- that v has no children, 5. SIBL [X ] contains the location of the next sibling of v. The condition SIBL (& ] = NULL indicates ha V is the last child of its parent, 4 ROOT contains the location of the root of the tree T. The representation discussed ab will contain exactly three fiel The procedure of represent SN Pointed out that each node of 7, regardless of the number of children general tree in the memory af tha.

You might also like