Notes for Graph Theory

Size: px
Start display at page:

Download "Notes for Graph Theory"

Transcription

1 Notes for Grph Theory These re notes I wrote up for my grph theory clss in 06. They contin most of the topics typiclly found in grph theory course. There re proofs of lot of the results, ut not of everything. I ve designed these notes for students tht don t hve lot of previous experience in mth, so I spend some time explining certin things in more detil thn is typicl. My writing style is lso pretty informl. If you see nything wrong (including typos), plese send me note t heinold@msmry.edu. Lst updted April, 08.

2 Contents Bsics 4. Wht is grph? Common grphs Sugrphs Connectedness Other importnt terminology Grph isomorphism New grphs from old grphs Proofs, Constructions, Algorithms, nd Applictions 6. Bsic results nd proving things out grphs Constructions Grph Representtions Algorithms Applictions of grphs Biprtite Grphs nd Trees 0. Biprtite grphs Trees Spnning trees Minimum spnning trees Shortest pths Eulerin nd Hmiltonin grphs Eulerin circuits Hmiltonin cycles Showing grph hs Hmiltonin cycle The Trveling Slesmn Prolem nd NP Completeness Coloring Definitions nd exmples Properties Applictions

3 CONTENTS 5.4 Edge coloring Further detils on coloring Plnr Grphs Definitions nd properties More on plnrity Emedding grphs on surfces Mtchings nd Covers 8 7. Definitions nd properties Biprtite mtching nd the Augmenting Pth Algorithm More on iprtite mtchings Hll s theorem Weighted iprtite mtching Stle mtching More out mtching Digrphs Definitions nd properties Connectedness of digrphs Directed cyclic grphs Tournments Connectivity 0 9. Definitions nd properties Menger s theorem Network flow

4 Chpter Bsics. Wht is grph? Grphs re networks of points nd lines, like the ones shown elow. They re useful in modeling ll sorts of rel world things, s we will see, s well s eing interesting in their own right. While the figure ove hopefully gives us resonly good ide of wht grph is, it is good to give forml definition to resolve ny miguities. Definition. A grph is pir (V, E), where V is set of ojects clled vertices nd E is set of two element susets of V clled edges. So grph is defined purely in terms of wht its vertices (points) re, nd which vertices re connected to which other vertices. Ech edge (line) is defined y its two endpoints. It doesn t mtter how you drw the grph; ll tht mtters is wht is connected to wht. For instnce, shown elow re severl wys of drwing the sme grph. Notice tht ll three hve the sme structure of string of vertices connected in row. For the second nd third exmples ove, we could imgine moving vertices round in order to strighten out the grph to look like the first exmple. Notice in the third exmple tht edges re llowed to cross over ech other. In fct, some grphs cn t e drwn without some edges crossing. Edges re lso llowed to curve. Rememer tht we re only concerned with which vertices re connected to which other ones. We don t cre exctly how the edges re drwn. In fct, we don t even hve to drw grph t ll. The grph ove cn e simply defined y sying its vertices re the set V = {,, c, d, e} nd its edges re the set E = {, c, cd, de}. However, we will usully drw our grphs insted of defining them with sets like this. 4

5 CHAPTER. BASICS 5 Importnt terminology nd nottion The terms nd nottions elow will show up repetedly. We will usully denote vertices with single letters like u or v. We will denote edges with pirs of letters, like uv to denote the edge etween vertices u nd v. We will denote grphs with cpitl letters, like G or H. Two vertices tht re connected y n edge re sid to e djcent. An edge is sid to e incident on its two endpoints. The neighors of vertex re the vertices it is djcent to. The degree of vertex is the numer of edges it is n endpoint of. The nottion deg(v) denotes the degree of vertex v. The set of vertices of grph G, clled its vertex set, is denoted y V (G). Similrly, the edge set of grph is denoted y E(G). For exmple, in the grph elow, the ottommost edge is etween vertices d nd e. We denote it s edge de. Tht edge is incident on d nd e. Vertex d is djcent to vertex e, s well s to vertices nd c. The neighors of d re, c, nd e. And d hs degree. c d e Finlly, in these notes, ll grphs re ssumed to e finite nd nonempty. Infinite grphs re interesting, ut dd quite few complictions tht we won t wnt to other with here. Multigrphs It is possile to hve n edge from vertex to itself. This is clled loop. It is lso possile to hve multiple edges etween the sme vertices. We use the term multiple edge to refer to edges tht shre the sme endpoints. In the figure elow, there is loop t vertex nd multiple edges (three of them) etween c nd d. d c Loops nd multiple edges cuse prolems for certin things in grph theory, so we often don t wnt them. A grph which hs no loops nd multiple edges is clled simple grph. A grph which my hve loops nd multiple edges is clled multigrph. In these notes, we will often use the term grph, hoping it will e cler from the context whether loops nd multiple edges re llowed. We will use the terms simple grph nd multigrph when we wnt to e explicitly cler. Note tht loops nd multiple edges don t fit our erlier definition of edges s eing two-element susets of the vertex set. Insted, multigrph is defined s triple consisting of vertex set, n edge set, nd reltion tht ssigns ech edge two vertices, which my or my not e distinct. Note lso tht loops count twice towrd the degree of vertex.

6 CHAPTER. BASICS 6. Common grphs This section is rief survey of some common types of grphs. Pths A grph whose vertices re rrnged in row, like in the exmples elow, is clled pth grph (or often just clled pth). P P P 4 P 5 Formlly, the pth P n hs vertex set {v, v,... v n } nd edge set {v i v i+ : i=,,... n}. Cycles If we rrnge vertices round circle or polygon, like in the exmples elow, we hve cycle grph (often just clled cycle). C C C C 4 C 5 C 6 Another wy to think of cycle is s pth where the two ends of the pth re connected up, like shown elow. Formlly, the cycle C n hs vertex set {v, v,... v n } nd edge set {v i v i+ : i=,,... n} {v n v }. Complete grphs A complete grph is simple grph in which every vertex is djcent to every other vertex. K K K K 4 K 5 K 6 Formlly, complete grph K n hs vertex set {v, v,... v n } nd edge set {v i v j : i < j n}. Note: Notice tht some grphs cn e clled y multiple nmes. For instnce, P nd K re the sme grph. Similrly, C nd K re the sme grph, often clled tringle.

7 CHAPTER. BASICS 7 Strs A str is grph tht consists of centrl vertex nd zero or more outer vertices of degree ll djcent to the centrl vertex. There re no other edges or vertices in the grph. Some exmples re shown elow. Formlly, str S n hs vertex set {v 0 } {v i : i n} nd edge set {v 0 v i : i n}. The Petersen grph The Petersen grph is very specific grph tht shows up lot in grph theory, often s counterexmple to vrious would-e theorems. Shown elow, we see it consists of n inner nd n outer cycle connected in kind of twisted wy. Regulr grphs A regulr grph is one in which every vertex hs the sme degree. The term k-regulr is used to denote grph in which every vertex hs degree k. There re my types of regulr grphs. Shown elow re -regulr, -regulr, nd 4-regulr grph. Others There re vrious other clsses of grphs. A few exmples re shown elow. Mny hve fun nmes like cterpillrs nd clws. It is not necessry to lern their nmes. Clw Empty grph Complete iprtite

8 CHAPTER. BASICS 8 Wheel Grid Cterpillr Squre of cycle Möius-Kntor Grötzsch. Sugrphs A sugrph is prt of grph, where we tke some of its vertices nd edges. Here is the forml definition. Definition. A grph H is sugrph of grph G provided the vertices of H re suset of the vertices of G nd the edges of H re suset of the edges of G. Shown elow on the left is grph. The prts of the originl grph tht re not prt of the sugrph re shown in gry nd dshed lines here, though usully they re just left out. Note tht if n edge is prt of sugrph, oth of its endpoints must e. It doesn t mke sense to hve n edge without n endpoint. Induced sugrphs Often the sugrphs we will e interested in re induced sugrphs, where whenever vertex is included, the sugrph must lso include ll of the edges of the originl grph incident on tht vertex. Below on the left we hve grph followed y two sugrphs of it. The first sugrph is not induced since it includes vertices,, c, nd d, ut not ll of the edges from the originl grph etween those vertices, such s edge c. The second sugrph is induced.

9 CHAPTER. BASICS 9 c c c d e d d Removing vertices Quite often, we will wnt to remove vertices from grph. Whenever we do so, we must lso remove ny edges incident on those vertices. Shown elow is grph nd two sugrphs otined y removing vertices. c c c In the middle grph we hve removed the vertex, which mens we hve to remove its four edges. In the right grph, we hve removed vertices nd c, which hs the effect of reking the grph into two pieces. If G is grph nd S is suset of its vertices, we will use the nottion G S for the grph otined y removing the vertices of S. If S consists of just single vertex v, we will write G v insted. And if we re removing just single edge e from grph, we will denote tht y G e. Specil sugrphs Pths nd cycles We will often e interested in pths nd cycles in grphs. Any time we sy grph contins pth or contins cycle, wht we men is tht it hs sugrph tht is pth or cycle. Exmples of pth nd cycle in grph re highlighted elow. Cliques A sugrph tht is complete grph is clled clique. It is sugrph in which every vertex in the sugrph is djcent to every other vertex in the sugrph. For exmple, in the grph elow we hve 4-clique in the lower left nd -clique (usully clled tringle) in the upper right. One wy to think out cliques is s follows: Suppose we hve grph representing socil network. The vertices represent people, with n edge etween two vertices mening tht those people know ech other. A clique in this grph is group of people tht ll know ech other.

10 CHAPTER. BASICS 0 Independent sets The opposite of clique is n independent set. It is collection of vertices in grph in which no vertex is djcent to ny other. Keeping with the socil network exmple, n independent set would e collection of people tht re ll strngers to ech other. An independent set is highlighted in the grph elow. Grph theorists re interested in the prolem of finding the lrgest clique nd lrgest independent set in grph, oth of which re difficult to find in lrge grphs..4 Connectedness Shown elow on the left is connected grph nd on the right disconnected grph. We see intuitively tht disconnected grph is in multiple pieces, ut how would we define this rigorously? The key feture of connected grph is tht we cn get from ny vertex to ny other. This is how we define connectivity. Formlly, we hve the following: Definition. A grph is connected provided there exists pth in the grph etween ny two vertices. Otherwise, the grph is disconnected. To reiterte the defining feture of connected grph is tht it is possile to get from ny vertex to ny other. Lter on, when we look t proofs, if we wnt to prove grph is connected, we will show tht no mtter wht vertices we pick, there must e pth etween them. The pieces of disconnected grph re clled its components. For instnce, in the disconnected grph ove on the right, the three components re the tringle, the two vertices on the right connected y n edge, nd the single vertex t the top. Just like with connectivity, we hopefully hve cler ide of wht piece or component of grph is, ut how would we define it precisely? Before reding on, try to think out how you would define it. One possile definition might e tht component is connected sugrph. But tht isn t quite right, s in the grph ove on the right there re more thn connected sugrphs. For instnce, the ottom of the tringle is connected sugrph ut not component. The trick is tht component is connected sugrph tht is s lrge s possile tht there is no other vertex tht could e dded to it nd hve it still remin connected. Mthemticins use the term mximl for situtions like this. A component is mximl connected sugrph, one tht cnnot e mde ny lrger nd still remin connected. Here is the forml definition. Definition 4. A component of grph is mximl connected sugrph. Another wy to think out component is tht it is connected sugrph tht is not contined in ny other connected sugrph. Note tht connected grph hs one component. Also, component tht consists of single vertex is clled n isolted vertex.

11 CHAPTER. BASICS.5 Other importnt terminology Cut vertices nd cut edges Here re two importnt types of vertices nd edges. Definition 5. A cut vertex of grph is vertex which, if deleted, reks the grph into more components thn it originlly hd. A cut edge is defined nlogously. It is n edge which, if deleted, reks the grph into more components thn it originlly hd. In prticulr, removing cut vertex or cut edge from connected grph will disconnect the grph. For exmple, in the grph elow on the left,,, nd c re cut vertices, s deleting ny one of them would disconnect the grph. Similrly, since deleting edge c disconnects the grph, tht mkes c cut edge. There re no other cut vertices nd cut edges in the grph. c Cut vertices nd cut edges ct like ottlenecks when it comes to connectivity. For instnce, ny pth in the grph ove from the leftmost to the rightmost vertices must pss through,, c, nd the edge c. Removing cut vertex could rek connected grph into two components or possily more. For instnce, removing the center of str will rek vertex into mny components. Removing cut edge cn only rek connected grph into two components. Distnce In grph, the distnce etween two vertices is mesure of how fr prt they re. Definition 6. The distnce etween two vertices, denoted d(u, v), is the length of the shortest pth etween u nd v in the grph. It is essentilly how mny steps the vertices re wy from ech other. For exmple, in the grph elow,, c, nd d re t distnce of from. Vertex e is t distnce of from, nd vertex f is t distnce of from. c d e f Notice, for instnce tht tht there re multiple pths from to d, ut the shortest pth is of length, so tht is the distnce..6 Grph isomorphism The term isomorphism literlly mens sme shpe. It comes up in mny different rnches of mth. In grph theory, when we sy two grphs re isomorphic, we men tht they re relly the sme grph, just drwn or presented possily differently. For exmple, the figure elow shows two grphs which re isomorphic to ech other.

12 CHAPTER. BASICS In oth grphs, ech vertex is djcent to ech other vertex, so these re two isomorphic copies of K 4. For simple exmple like this one, it s not too hrd to picture morphing one grph into the other y sliding vertices round. But for grphs with mny vertices, this pproch is not fesile. It cn ctully e pretty tricky to show tht two lrge grphs re isomorphic. For instnce, the three grphs elow re ll isomorphic, nd it is not t ll trivil to see tht. Before we go ny further, here is the forml definition: Definition 7. Grphs G nd H re isomorphic provided there exists one-to-one nd onto function f : V (G) V (H) such tht v is djcent to w in G if nd only if f (v) is djcent to f (w) in H. In other words, for two grphs to e isomorphic, we need to e le to perfectly mtch up the vertices of one grph with the vertices of the other, so tht whenever two vertices re djcent in the first grph, the vertices they re mtched up with must lso e djcent. And if those vertices re not djcent in the originl, the vertices they re mtched up with must not e djcent either. For exmple, we cn use the definition to show the grphs elow re isomorphic. e d x y c v w z To do this, we mtch up the vertices s follows: v w c x d z e y Written in function nottion, this mtching is f () = v, f () = w, f (c) = x, f (d) = z, nd f (e) = y. It is one-to-one nd onto. We lso need to check tht ll the edges work out. For instnce, is n edge in the left grph. Since nd re mtched with v nd w, we need vw to e n edge in the right grph, nd it is. Similrly, there is no edge from to e in the left grph. Since nd e re mtched to v nd y, we cnnot hve n edge in the right grph from v to y, nd there is none. Though it s little tedious, it s possile to check ll the edges nd nonedges in this wy. Showing two grphs re isomorphic cn e tricky, especilly if the grphs re lrge. If we just use the definition, there re mny possile mtchings we could try, nd for ech of those, checking tht ll the edges work out cn tke while. There re, however, lgorithms tht work more quickly thn this, nd it is ig open question in the field of grph lgorithms s to exctly how good these lgorithms cn e mde. On the other hnd, it cn often e pretty simple sometimes to show tht two grphs re not isomorphic. We need to find property tht the two grphs don t shre. Here is list of few properties one could use:

13 CHAPTER. BASICS If the two grphs hve different numer of vertices or edges If the two grphs hve different numers of components If the vertex degrees re not exctly the sme in ech grph If the grphs don t contin exctly the sme sugrphs Here is n exmple. Both grphs elow hve the sme numer of vertices, oth hve the sme numer edges, oth hve one component, nd oth consist of two vertices of degree, two vertices of degree, nd four vertices of degree. So the first three properties re no help. However, the right grph contins tringle, while the left grph does not, so the fourth property comes to our rescue. There re mny other possiilities esides the four properties ove. Sometimes, it tkes little cretivity. For exmple, the grphs elow re not isomorphic. Note tht they do oth hve the sme numer of vertices nd edges, nd in fct the degrees of ll the vertices re the sme in oth grphs. However, the right grph contins vertex of degree djcent to two vertices of degree, while tht is not the cse in the left grph. Another wy to pproch this is tht the left grph contins two pths of length 5 (the stright-line pth long the ottom, nd one strting with the top vertex nd then turning left long the pth), while the right grph just contins one pth of length 5..7 New grphs from old grphs This section explores few wys of using grphs to crete new grphs. Complements The complement of grph G is grph G with the sme vertex set s G, ut whose edges re exctly the opposite of the edges in G. Tht is, uv is n edge of G if nd only if uv is not n edge of G. Shown elow re grph nd its complement. One wy to think of the complement is tht the originl plus the complement equls complete grph. So we cn get the complement y tking complete grph nd removing ll the edges ssocited with the originl grph.

14 CHAPTER. BASICS 4 Union The union of two grphs is otined y tking copies of ech grph nd putting them together into one grph. Formlly, given grphs G nd H, their union G H hs vertex set V (G H) = V (G) V (H) nd edge set E(G H) = E(G) E(H). The sme ide works with unions of more thn two grphs. For instnce, shown elow is C 4 K K 4. Join The join of two grphs, G nd H, is formed y tking copy of G, copy of H, nd dding n edge from every vertex of G to every vertex of H. For exmple, shown elow on the left is type of grph clled wheel, which is K C 6. It consists of 6-cycle nd single vertex, with edges from tht single vertex to every vertex of the cycle. On the right we hve C 4 K. Formlly, the join G H hs vertex set V (G H) = V (G) V (H) nd edge set E(G H) = E(G) E(H) {gh : g V (G), h V (H)}. Line grph The line grph, L(G), of grph G is grph tht we crete from the edges of G. Ech edge of G ecomes vertex of L(G). Two vertices in L(G) re djcent if nd only if their corresponding edges in G shre n endpoint. Shown elow is n exmple of grph nd the construction of its line grph. To crete the line grph ove, we strt y mking vertex for ech edge of the originl grph. Then we crete the edges of the line grph ccording to the rule ove. For exmple, the top two edges of the originl grph shre n endpoint, so we will get n edge in the line grph etween the vertices representing those edges. Similrly, the digonl edge in the originl shres endpoints with 4 other edges, so in the line grph it will hve degree 4. Sometimes questions out edges of G cn e trnslted to questions out vertices of L(G). Crtesin product The Crtesin product grph is relted to the Crtesin product of sets. The sic ide is strting with two grphs G nd H, to get the Crtesin product G H, we replce ech vertex of G with n entire copy of H. We then dd

15 CHAPTER. BASICS 5 edges etween two copies provided there ws n edge in G etween the two vertices those copies replced. And we only dd edges etween the two copies etween identicl vertices in the copies. An exmple is shown elow. G H G H Notice how ech of the four vertices of G is replced with copy of the tringle, H. Then wherever there is n edge in G, we connected up the tringles, nd we do this y connecting up like vertices with like vertices. Formlly, the vertex set of the Crtesin product G H is V (G) V (H) (tht is, ll pirs (v, w), with v V (G) nd w V (H)). The edges of the Crtesin product re s follows: for ech v V (G) there is n edge etween (v, w ) nd (v, w ) if nd only if w w E(H); nd for ech w V (H), there is n edge etween (v, w) nd (v, w) if nd only if v v E(G). Here is nother exmple of Crtesin product grid grph. Here we hve leled the vertices with their Crtesin coordintes. (v, w ) (v, w ) (v, w ) (v 4, w ) w v v v v 4 w (v, w ) (v, w ) (v, w ) (v 4, w ) w (v, w ) (v, w ) (v, w ) (v 4, w ) P 4 P P 4 P Hypercues re importnt grphs defined y the Crtesin product. The first hypercue, Q is K. The second hypercue, Q is Q K, squre. The third hypercue Q is Q K, which gives grph representing n ordinry cue. In generl, Q n = Q n K for n. The first four re shown elow. The lst one is drwing of 4-dimensionl cue on flt plne. It is shown with the two copies of Q highlighted. In generl, ech hypercue comes from two copies of the previous hypercue connected up ccording to the Crtesin product rules. Note: Notice from the definition of the Crtesin product tht G H is isomorphic to H G.

16 Chpter Proofs, Constructions, Algorithms, nd Applictions. Bsic results nd proving things out grphs In these notes, we will cover numer of fcts out grphs. It s nice to e sure tht something is true nd to know why it is true, nd tht s wht mthemticl proof is for. Our proofs, like mny in mth, re designed to convince mthemticl reder tht result is true. To keep things succinct, we don t lwys include every detil, relying on the reder to fill in smll gps. The proofs themselves will often consist more of words thn of symols. Degree Sum Formul nd Hndshking Lemm Here is the first result tht mny people lern in grph theory. Theorem (Degree Sum Formul). In ny grph, the sum of the degrees of ll vertices is twice the numer of edges. Proof. Every edge contriutes to the totl degree sum, one for ech of its endpoints. Note tht if we wnt to e it more forml, we cn stte the result ove s follows: deg(v) = E(G). v V (G) In prticulr, the degree sum must e even. These leds to the following consequence, clled the Hndshking Lemm. Theorem (Hndshking Lemm). In every grph, there re n even numer of vertices of odd degree. Proof. If there were n odd numer of vertices of odd degree, then the totl degree sum would e odd, contrdicting the previous theorem. The Hndshking Lemm comes from the following: Suppose some people t prty shke hnds with others. Then there must e n even numer of people who shook n odd numer of hnds. Here the people re vertices, with n edge etween two vertices if the corresponding people shook hnds. To summrize: the sum of the degrees in ny grph is twice the numer of edges, nd grphs with n odd numer of odd-degree vertices re impossile. We will mke use of these results repetedly in these notes, so know them well. 6

17 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 7 An ppliction of the Degree Sum Formul Here is one use of the Degree Sum Formul. Theorem. If grph hs exctly two vertices of odd degree, then there must e pth etween them. Proof. If there were no pth etween the vertices, then they would lie in different components. Those components would then hve exctly one vertex of odd degree ech, contrdicting the Hndshking Lemm, s the components re themselves grphs. So there must e pth etween those vertices. The proof ove, like the proof of the Hndshking Lemm, is n exmple of proof y contrdiction. We strt y ssuming tht the result is flse, nd end up contrdicting something we know must e true. The conclusion then is tht our result must e true. Proof y contrdiction is useful nd powerful technique for proving things. Another theorem out vertex degrees Continuing with vertex degrees, here is nother result tht might e little surprising. Theorem 4. In every simple grph with t lest two vertices, there re t lest two vertices with the sme degree. Proof. Suppose not: suppose tht ll n vertices hve different degrees. Since the grph is simple, the lrgest possile degree of vertex is n. Since ll the degrees re different, those degrees must e 0,,,..., n, with exctly one vertex of ech degree. A vertex with degree 0 is djcent to nothing, nd vertex with degree n is djcent to every vertex except itself. But these sttements re incomptile with ech other. A grph cn t contin oth vertex djcent to every other vertex nd vertex djcent to nothing. So we hve contrdiction, mening tht some vertices must shre the sme degree. Sometimes, with proofs like these, it helps to look t specific exmple. Suppose we hve n = 5 vertices. Then if the degrees re ll different, the degrees must e 0,,,, nd 4. Tht degree 4 vertex is djcent to ll of the others, including the degree 0 vertex, which isn t possile. So the degrees must e five integers in the rnge from 0 to or five integers in the rnge from to 4, mening there will e repeted degree. Notice where in the proof the fct tht the grph is simple is used nmely, in gurnteeing tht we hve to hve vertex djcent to ll others long with vertex of degree 0. If we remove the requirement tht the grph e simple nd llow loops nd multiple edges, then the result turns out to e flse. It s nice exercise to try to find counterexmples in tht cse. Notice lso tht we use proof y contrdiction here gin. Some mthemticins (ut not this uthor) feel tht proofs y contrdiction re poor mthemticl style nd tht direct proofs should e preferred. The proof ove could e reworked into direct proof using the pigeonhole principle. It s nother nice exercise to try to do tht. A proof out connectedness To get some more prctice with proofs, here is nother result, this one out connectedness. Theorem 5. If grph is disconnected, then its complement is connected. Proof. Cll the grph G. Since it is disconnected, it hs to hve t lest two vertices. Pick ny two vertices u nd v. We need to show tht there is pth etween them in G. First, if u nd v re different components of G, then uv E(G), which mens uv E(G) nd hence we hve pth from u to v in G. On the other hnd, if u nd v re in the sme component of G, then pick some other vertex w in different component. Then uw nd wv re not in E(G), mening they re in E(G). Thus we hve pth in G etween u nd v tht goes through w.

18 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 8 The proof is only couple of lines, ut fir mount of thinking nd work goes into producing those lines. To strt, we go stright to the definition of connectedness. Specificlly, to show G is connected, we hve to show there is pth etween ny two vertices. Let s cll them u nd v, s we did in the proof. Next, it helps to drw picture. We know tht G is disconnected, so we might try picture like the one elow. G G The picture shows two components, though there might e more. We know tht when we tke the complement, ny two components of the originl will e joined together y ll possile edges etween vertices. So if u nd v strted out in different components, they would e djcent in the complement. So tht s one cse tken cre of. But now wht if u nd v re in the sme component? We cn t forget out tht cse. If u nd v re in the sme component, then there is pth etween them in G, ut mye they end up seprted when we tke the complement. This turns out not to e prolem. Recll tht we hve ll possile edges etween ny two components, so we cn crete two-step pth from u to v y jumping from u to some vertex w in different component nd then ck to v. To summrize: We re trying to find pth etween ny two vertices u nd v in G. We hve roken things into two cses one where u nd v re in different components, nd one where u nd v re in the sme component. When doing proofs, it is often useful to rek things into cses like this. And it is importnt to mke sure tht every possile cse is covered. The theorem ove sys tht the complement of disconnected grph is connected. Wht if we try chnging it round to sk if the complement of connected grph is disconnected? It turns out not to e true in generl. To show this we need single counterexmple, like the one elow, showing C 5 nd its complement, oth of which re connected. In generl, to prove something requires logicl rgument, while to disprove something requires just single counterexmple. An if-nd-only-if proof Here is nother sttement, this one iconditionl (if-nd-only-if sttement). Theorem 6. An edge in grph is cut edge if nd only if it is prt of no cycle. It is essentilly two sttements in one, mening there re two things to prove, nmely:. If e is cut edge, then it is prt of no cycle.. If e is prt of no cycle, then it is cut edge. It siclly sys tht eing cut edge is equivlent to not eing prt of cycle. Those two concepts cn e used interchngely. Here is the proof of the theorem:

19 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 9 Proof. Cll the grph G, cll the cut edge e, nd let its endpoints e clled u nd v. First, ssume e is cut edge. Then deleting it reks the grph into more thn one component, with u in one component nd v in nother. Suppose e were prt of cycle. Then going the other wy long the cycle from u to v, voiding edge e, would provide pth from u to v, mening those vertices re in the sme component, contrdiction. Thus e cnnot e prt of cycle. Next, ssume e is prt of no cycle. Then there cnnot e ny pth etween u nd v other thn long edge e, s otherwise we could comine tht pth long with e to crete cycle. Thus, if we delete e, there is no pth from u to v, mening u nd v re in different components of G e. So e is cut edge. Often when trying to understnd proof like this, or in trying to come up with it yourself, it helps to drw picture. Here is picture to help with visulizing wht hppens in the proof. u e v Mthemticl induction Consider the following prolem: Alice nd her husnd Bo re t prty with other couples. At the prty some people shke hnds with some others. No one shkes their own hnd or the hnd of their prtner. Alice sks everyone else how mny hnds they ech shook, nd everyone gives different nswer. How mny different hnds did Bo shke? This seems like izrre question, like it shouldn t e nswerle. Nevertheless, let s strt y modeling it with grph. The people ecome vertices nd edges indicte hndshkes. The degree of vertex is how mny hnds tht vertex s corresponding person shook. See elow on the left for wht our grph initilly looks like. 0 6 A B A B 4 5 There re 4 couples nd 8 people totl. Alice sks the other 7 people nd gets 7 different nswers. Tht mens the nswers must e the integers from 0 to 6. Let p 0, p,..., p 6 e the nmes of the people tht shook 0,,..., 6 hnds, respectively. Person p 6 must hve shken hnds with everyone t the prty except p 6 nd the prtner of p 6. Tht mens tht the prtner of p 6 must e p 0, since everyone else must hve shken t lest one hnd (nmely the hnd of p 6 ). It s importnt to note tht p 0 nd p 6 re not Alice nd Bo (or Bo nd Alice). Why? Rememer tht Alice is not included mong p 0, p,..., p 6, nd if Bo were p 0 or p 6, tht would mke Alice p 6 or p 0 since p 0 nd p 6 re prtners. Now consider p 5. Tht person shook hnds with everyone except p 5, the prtner of p 5 nd p 0. This mens tht p must e the prtner of p 5, since everyone else must hve shken t lest two hnds (nmely the hnds of p 5 nd p 6. And y the sme rgument s ove, p nd p 5 re not Alice nd Bo.

20 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 0 A similr rgument to the ones we hve just looked t show tht p 4 nd p re prtners nd they re not Alice nd Bo. This mens tht Bo must e p, hving shken hnds. The grph of this ends up looking like the one ove on the right. The generl cse Suppose we generlize this to prty of n couples. How mny hnds must Bo hve shken in tht cse? The nswer is n. We cn show this y generlizing nd formlizing the rgument ove using mthemticl induction. As ove, we model the prty y grph where the people re vertices nd edges indicte hndshkes. The se cse is prty with n = couple, just Alice nd Bo. Since they re prtners, they don t shke ech other s hnds. So Bo shkes no hnds, which is the sme s n with n =. Now ssume tht t ny prty of n couples stisfying the setup of the prolem, Bo shkes n hnds. Consider then prty of n + couples. We need to show tht Bo shkes exctly n hnds in this prty. Since the nswers tht Alice gets re ll different, they must e the integers from 0 through n. Let p 0, p,..., p n e the nmes of the people tht shook 0,,..., n hnds, respectively. Then p n must hve shken hnds with everyone else t the prty except p n nd the prtner of p n. Tht is, vertex p n is djcent to ll vertices of the grph except itself nd one other vertex. Tht other person/vertex, must e p 0. So p n nd p 0 re prtners. As efore, p 0 nd p n cnnot e Alice nd Bo (or Bo nd Alice). Now remove p 0 nd p n from the prty/grph. Doing so leves grph corresponding to n couples, where the degree of ech vertex hs een reduced y exctly. This prty/grph stisfies the induction hypothesis nmely, it is prty of n couples nd everyone tht Alice sks hs different degree ecuse their degrees were ll different in the originl nd we hve sutrcted precisely from ll of those degrees. By the induction hypothesis, Bo must hve shken n hnds mong this prty. Therefore in the originl prty, Bo shook n hnds, those eing the n in the smller prty long with the hnd of p n. A little out induction If you hve never seen induction, then the preceding my likely mke no sense to you. Consider picking up ook on Discrete Mth to lern some induction. But even if you hve seen induction efore, the preceding my seem odd. It lmost seems like cheting, like we didn t relly prove nything. The key here is the work tht goes into setting the proof up. In prticulr, when we remove couple from the grph to get to the smller cse, we cn t remove just ny couple. We need to remove couple tht preserves the prmeters of the prolem, especilly the prt out Alice getting ll different nswers. The hrd work comes in plnning things out. The finished product, the proof, ends up reltively short.. Constructions Often we will wnt to uild grph tht hs certin properties. This section contins few exmples. Constructing multigrph with given degrees The first question we will nswer is this: given sequence of integers, is there multigrph for which those integers re the degrees of its vertices? The nswer is yes, provided the sequence stisfies the Hndshking Lemm, nmely tht there must e n even mount of odd integers in the sequence. We cn show this y constructing the grph. To see how it works, it helps to use n exmple. Let s tke the sequence 0,,,, 5, 7, 8. Strt y creting one vertex for ech integer in the sequence. Then pir off the first two odd integers, nd, nd dd n edge etween their corresponding vertices. Then do the sme for the other two odd integers, 5 nd 7. Adding the edges etween pirs of odd degree vertices essentilly tkes cre of the odd prt of their degrees, leving only n even numer to worry out. We cn use loops to tke cre of those even numers since ech loop dds to vertex s degree. See the figure elow for the process.

21 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS This technique works in generl. We strt y piring off the first two odd integers nd dding n edge etween their vertices, then piring off the next two odd integers, etc. until we hve worked through ll the odd integers. It s possile to pir off ll the odds since we know there must e n even numer of them y the Hndshking Lemm. After doing this, dd loops to ech vertex until its degree mtches it sequence vlue. Constructing regulr grphs Our second exmple is to nswer the following question: given integers r nd n, is it possile to construct n r-regulr simple grph with n vertices? The nswer is yes provided r n nd t lest one of r nd n is even. We need r n since n is the lrgest degree vertex cn hve in simple grph, nd we need t lest one of r nd n to e even y the Hndshking Lemm. The construction is different depending on if r is even or odd. We ll do the even cse first. Strt y plcing n vertices round circle. This is 0-regulr grph on n vertices. To crete -regulr grph from it, join ech vertex to its two neighors. The grph creted this wy is the cycle C n. To crete 4-regulr grph, join ech vertex dditionlly to oth vertices tht re t distnce of from it long the circle. To crete 6-regulr grph, join ech vertex to oth vertices tht re t distnce of from it long the circle. This sme ide cn e extended to crete lrger regulr grphs of even degree. The grph elow on the left is n exmple of the 4-regulr grph on vertices creted y this process. To crete regulr grph of odd degree, use the exct sme process, ut dditionlly connect ech vertex to the vertex on the circle dimetriclly opposite to it. Shown ove on the right is 5-regulr grph on vertices. Note tht in the figure, the lines ll cross t the center, giving the illusion of vertex there, ut there is not one. It is worth descriing this construction formlly. Here is one wy to do it: Cll the vertices v 0, v,..., v n. For n r-regulr grph, where r is even, for ech vertex v i, dd edges from v i to v (i±k) mod n, for k =,,... r/. If r is odd, dd ll of those edges long with n edge from v i to v (i+n/) mod n. These grphs re clled Hrry grphs, fter the fmous grph theorist Frnk Hrry.

22 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS. Grph Representtions Grph theory hs lot of pplictions to rel prolems. Those prolems often re descried y grphs with hundreds, thousnds, or even millions of vertices. For grphs of tht size, we need wy of representing them on computer. There two wys this is usully done djcency mtrices nd djcency lists. Adjcency mtrix The ide is tht we use mtrix to keep trck of which vertices re djcent to which other vertices. An entry of in the mtrix indictes two vertices re djcent nd 0 indictes they ren t djcent. For instnce, here is grph nd its djcency mtrix: c d e 0 0 c e 0 0 c 0 0 d 0 0 d e Adjcency lists The second pproch to implementing grph is to use djcency lists. For ech vertex of the grph we keep list of the vertices it is djcent to. Here is grph nd its djcency lists: c e d : [, c, d ] : [, c, e ] c : [,, d ] d : [, c, e ] e : [, d ] Adjcency mtrices vs. djcency lists Adjcency mtrices mke it very quick to check if two vertices re djcent. However, if the grph is very lrge, djcency mtrices cn use lot of spce. For instnce,,000,000 vertex grph would require,000,000,000,000 entries, hving trillion totl entries. This would require n uncceptly lrge mount of spce. Adjcency lists use lot less spce thn djcency mtrices if vertex degrees re reltively smll, which is the cse for mny grphs tht rise in prctice. For this reson (nd others) djcency lists re used more often thn djcency mtrices when representing grph on computer. Coding grph clss Here is quick wy to crete grph clss in Python using djcency lists: clss Grph(dict): def dd(self, v): if v not in self: self[v] = []

23 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS def dd_edge(self, u, v): self[u].ppend(v) self[v].ppend(u) The clss inherits from the Python dictionry clss, which gives us numer of useful things for free. For instnce, if our grph is clled G with vertex '', then G[''] will give us the neighors of tht vertex. We hve creted two methods for the clss. The first one dds vertex. To do so, it first checks to mke sure we hven t lredy dded tht vertex to the grph, nd then it cretes n empty djcency list for it. The other method is for dding n edge. We do tht y dding ech endpoint to the other endpoint s djcency list. Here is n exmple of how to crete grph nd find out some things out it. G = Grph() G.dd('') G.dd('') G.dd('c') G.dd_edge('', '') G.dd_edge('', 'c') print(g['']) print(len(g[''])) print(len(g)) print('' in G['']) for v in G: print(v) # the neighors of vertex # the degree of vertex # the totl numer of vertices in G # determine if vertices nd re djcent # loop over ll the vertices.4 Algorithms One of the most importnt prts of grph theory is the study of grph lgorithms. An lgorithm is, roughly speking, step-y-step process for ccomplishing something. For instnce, the processes students lern in grde school for dding nd multiplying numers y hnd re exmples of lgorithms. In grph theory, there re lgorithms to find vrious importnt things out grph, like finding ll the cut edges or finding the shortest pth etween two vertices. Mny of the lgorithms we will study will require us to visit the vertices of the grph in systemtic wy. There re two relted lgorithms for this, redth-first serch (BFS) nd depth-first serch (DFS). The sic ide of ech of these is we strt somewhere in the grph, then visit tht vertex s neighors, then their neighors, etc., ll the while keeping trck of vertices we ve lredy visited to void getting stuck in n infinite loop. The figure elow shows the order in which BFS nd DFS visit the vertices of grph, strting t vertex. c 4 d e 5 c 8 7 d e f 6 g 7 h 8 i 9 j 0 k m l f g h 0 i 9 j 6 k 5 4 m l Notice how BFS fns out from vertex. Every vertex t distnce from is visited efore ny vertex t distnce. Then every vertex t distnce is visited efore ny vertex t distnce. DFS, on the other hnd, follows

24 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 4 pth down into the grph s fr s it cn go until it gets stuck. Then it cktrcks to its previous loction nd tries serching from there some more. It continues this strtegy of following pths nd cktrcking. These re the two key ides: BFS fns out from the strting vertex, doing systemtic sweep. DFS just goes down into the grph until it gets stuck, nd then cktrcks. If we re just trying to find ll the vertices in grph, then oth BFS nd DFS will work eqully well. However, if we re serching for vertices with prticulr property, then depending on where those vertices re locted in reltion to the strt vertex, BFS nd DFS will ehve differently. BFS, with its systemtic serch, will lwys find the closest vertex to the strting vertex. However, ecuse of its systemtic sweep, it might tke BFS while efore it gets to vertices fr from the strting vertex. DFS, on the other hnd, cn very quickly get fr from the strt, ut will often not find the closest vertex first. The code Here is some code implementing BFS nd DFS: def fs(g, v): found = {v} witing = [v] while witing: w = witing.pop(0) for x in G[w]: if x not in found: found.dd(x) witing.ppend(x) return found def dfs(g, v): found = {v} witing = [v] while witing: w = witing.pop() for x in G[w]: if x not in found: found.dd(x) witing.ppend(x) return found The function tkes two prmeters, grph G nd vertex v, which is the vertex we strt the serch t. We mintin two lists: one clled witing nd one clled found, which is ctully set. Initilly, oth strt out with only v in them. We then continully do the following: pop off vertex from the witing list nd loop through its neighors, dding ny neighor we hven t lredy found into oth the found set nd witing list. The found set keeps trck of ll the vertices the lgorithm hs discovered. The witing list keeps trck of which vertex we should visit next. The while loop keeps running s long s the witing list is not empty, i.e. s long s there re still vertices we hven t explored. The two lgorithms differ only in how they choose the next vertex to visit. DFS visits the most recently dded vertex, while BFS visits the erliest dded vertex. This is where we use witing.pop(0) versus witing.pop(). For those reders fmilir with dt structures, BFS trets the list of vertices to visit s queue, while DFS trets the list s stck. Let s run BFS on the grph elow, strting t vertex. The first thing the lgorithm does is dd ech of the neighors of to the witing list nd found set. So t this point, the witing list is [, c, d, e]. BFS lwys visits the first vertex in the witing list, so it visits next nd dds its neighors to the list nd set. So now the witing list is [c, d, e, f, g]. For the next step, we tke the first thing off the witing list, which is c nd visit it. We dd its neighors h nd i to the list nd set. This gives us witing list of [d, e, f, g, h, i]. As the process continues, the witing list will strt shrinking nd the found set will eventully include ll the vertices. c d e f g h i j k l m

25 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 5 Now let s look t the first few steps of DFS on the sme grph, strting t vertex. Like BFS, it strts y dding the neighors of to the witing list nd found set. After the first step, the witing list is [, c, d, e]. DFS then visits the lst thing on the list, e, s opposed to BFS, which visits the first. DFS dds the neighors of e, which re j, k, nd l to the found set nd witing list, which is now [, c, d, j, k, l]. It visits the lst vertex in the witing list l, nd dds its neighors m nd n to list nd set. This gives witing list of [, c, d, j, k, m]. We then visit vertex m. It hs only one neighor k, which hs lredy een found, so we do nothing with tht neighor. This is how we void getting stuck in n infinite loop ecuse of the cycle. The witing list is now [, c, d, j, k] nd the found set is {,, c, d, e, j, k, l, m}. We visit k next. It hs neighor e, ut we don t dd e to the witing list ecuse e is in the visited set lredy. The witing list is now [, c, d, j]. The next vertex visited is j. Notice how the lgorithm hs essentilly cktrcked to e nd is now serching in different direction from e. The lgorithm continues for severl more steps from here, ut for revity, we won t include them. Here re severl importnt notes out this code: The code hs een deliertely kept smll. It hs the effect of finding ll the vertices tht re in the sme component s the strting vertex. In the next section, we will see how to modify this code to do more interesting things. The method requires us to pss it strting vertex. If we would rther not hve to specify it, cn use v = next(iter(g)) s the first line, which will pick vertex from the grph for us. We could use list for found insted of set, ut the result would e sustntilly slower for lrge grphs. The prt where we check to see if vertex is lredy in the found set is the key. The lgorithm Python uses to check if something is in set is much fster thn the corresponding list-checking lgorithm. There re vriety of other wys to implement BFS nd DFS. In prticulr, you will often see DFS implemented recursively. Applictions of BFS nd DFS The lgorithms s presented ove ct s something we cn uild on for more complex pplictions. Smll modifictions to them will llow us to find numer of things out grph, such s shortest pth etween two vertices, the grph s components, its cut edges, nd whether the grph contins ny cycles. As n exmple, here is modifiction of DFS to determine if there is pth etween two vertices in grph: def is_connected_to(g, u, v): found = [u] witing = [u] while witing: w = witing.pop() for x in G[w]: if x == v: return True elif x not in found: found.ppend(x) witing.ppend(x) return Flse The min chnge is when we look t the neighors of vertex, if the vertex we re looking for shows up, then we stop immeditely nd return True. If we get ll the wy through the serch nd hven t found the vertex, we return Flse. Shortest pth Here is nother exmple, this one modifiction to BFS to return the shortest pth etween two vertices in grph. The key difference etween this code nd the BFS code is tht we replce the found set with Python

26 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 6 dictionry tht keeps trck of ech vertex s prent. Tht is, insted of keeping trck only of the vertices tht we hve found, we lso keep trck of wht vertex we were serching from t the time. This llows us, once we find the vertex we re looking for, to cktrck from vertex to vertex to give the exct pth. def shortest_pth(g, u, v): witing = [u] prent = {u : None} # A dictionry insted of list while witing: w = witing.pop(0) for x in G[w]: # If we've found our trget, then cktrck to get pth if x == v: Pth = [x] x = w while x!= None: Pth.ppend(x) x = prent[x] Pth.reverse() return Pth if x not in prent: prent[x] = w witing.ppend(x) return [] # return n empty list if there is no pth etween the vertices Note lso tht we use BFS here nd not DFS. Rememer tht BFS lwys serches ll the vertices t distnce, followed y ll the vertices t distnce, etc. So whtever pth it finds is gurnteed to e the shortest. Replcing BFS with DFS here would give still us pth etween the vertices, ut it quite likely will e long nd mendering. Components The sic versions of BFS nd DFS tht we presented return ll the vertices in the sme component s the strting vertex. With little work, we cn modify this to return list of ll the components in the grph. We do this y looping over ll the vertices in the grph nd running BFS or DFS using ech vertex s strting vertex. Of course, once we know wht component vertex elongs to, there is no sense in running serch from it, so in our code we ll skip vertices tht we hve lredy found. Here is the code: def components(g): component_list = [] found = set() for w in G: if w in found: continue # skip vertices whose components we lredy know # now run DFS strting from vertex w found.dd(w) component = [w] witing = [w] while witing: v = witing.pop(-) for u in G[v]: if u not in found: witing.ppend(u) component.ppend(u) found.dd(u) component_list.ppend(component) return component_list

27 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 7.5 Applictions of grphs Grphs lend themselves to solving wide vriety of prolems. We will see numer of pplictions in lter chpters. In this section we introduce few pplictions of mteril we hve lredy covered. Grph theory for solving n old puzzle This first ppliction doesn t relly pply to the rel world, ut it does demonstrte how we cn model something with grph. It is out the following puzzle tht is over 000 yers old: A trveler hs to get wolf, got, nd cge cross river. The prolem is tht the wolf cn t e left lone with the got, the got cn t e left lone with the cge, nd the ot cn only hold the trveler nd single niml/vegetle t once. How cn the trveler get ll three items sfely cross the river? To model this prolem with grph, it helps to think of the possile sttes of the puzzle. For exmple, the strting stte consists of the trveler, wolf, got, nd cge ll on one side of the river with the other side empty. We cn represent this stte y the string Twgc, where T, w, g, nd c stnd for the trveller, wolf, got, nd cge. The verticl line represents the river. The stte where the wolf nd cge re on the left side of the river nd the trveller nd got re on the right side would e represented y the string wc Tg. To model this s grph, ech stte/string ecomes vertex, nd we hve n edge etween two vertices provided it is possile, following the rules of the puzzle, to move from the stte represented y the one vertex to the stte represented y the other in one crossing. For instnce, we would hve n edge etween Twgc nd wc Tg, ecuse in we cn get from one to the other in one crossing y sending the trveler nd the got cross the river. Shown elow is the grph we otin. w Tgc Twg c Twgc wc Tg Twc g g Twc Tg wc Twgc c Twg Tcg w We hve omitted impossile sttes, like like wg Tc, from the grph ove. Once we hve grph representtion, we could use n lgorithm like DFS or BFS to serch for pth from the strting stte, Twgc, to the ending stte, Twgc. Now oviously tht would e overkill for this prolem, ut it could e used for more complex puzzle. For exmple, you my hve seen the following wter jug prolem: You hve two jugs of certin sizes, mye 7-gllon nd n -gllon jug, nd you wnt to use them to get exctly 6 gllons of wter. You re only llowed to () fill up pil to the top, () dump pil completely out, or () dump the contents of one pil into nother until the pil is empty or the other is full. There is no estimting llowed. To model this s grph, the vertices re sttes which cn e represented s pirs (x, y) indicting the mount of wter currently in the two jugs. Edges represent vlid moves. For instnce, from the stte (5, ), one could go to (0, ) or (5, 0) y dumping out pil, one could go to (7, ) or (5, ) y filling pil up, or one could go to (0, 8) y dumping the first into the second. One note is tht these edges re one-wy edges. We will cover those lter when we tlk out digrphs. But the min point is tht with little work, we cn progrm in ll the sttes nd the rules for filling nd emptying pils, nd then run one of the serching lgorithms to find solution. This technique is useful numer of other contexts. For instnce, mny computer chess-plying progrms crete grph representing gme, where the sttes represent where ll the pieces re on the ord, nd edges represent

28 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 8 moves from one stte to nother. The progrm then serches s fr out in the grph s it cn go (it s ig grph), rnking ech stte ccording to some criteri, nd then choosing its fvorite stte to move to. Grphs nd movies From the Interntionl Movie Dtse (IMDB), it is possile to get file tht contins rther lrge numer of movies long with the people tht hve cted in ech movie. A fun question to sk is to find pth from one ctor X to nother Y, long the lines of X cted in movie with A who cted in movie with B who cted in movie with Y. There re ll sorts of things we could study out this, such s whether it is lwys possile to find such pth or wht the length of the longest pth is. We cn model this s grph where ech ctor gets vertex nd ech movie lso gets vertex. We then dd edges etween ctors nd the movies they cted in. The file is structured so tht on ech line there is movie nme followed y ll the ctors in tht movie. The entries on ech line re seprted y slshes, like elow: Princess Bride, The (987)/Guest, Christopher (I)/Gry, Willoughy/Cook,... Here is some code tht prses through the file nd fills up the grph: G = Grph() for line in open('movies.txt'): line = line.strip() L = line.split('/') G.dd(L[0]) for x in L[:]: G.dd(x) G.dd_edge(L[0], x) We cn then use modified BFS to find the shortest pth etween one ctor nd nother. Asking whether it is lwys possile to find pth is the sme s sking whether the grph is connected. It turns out not to e, ut it is mostly connected. Tht is, we cn run vrition of BFS or DFS to find the components of the grph, nd it turns out tht the grph hs one very lrge component, contining lmost ll of the ctors nd movies you hve ever herd over. The grph contins few dozen other smll components, corresponding to isolted movies ll of whose ctors ppered only in tht movie nd nowhere else. Word ldders A word ldder is pth from one word to nother y chnging one letter t time, with ech intermedite step eing rel word. For instnce, one word ldder from this to tht is this thin thn tht. We cn model this s grph whose vertices re words, with edges whenever two words differ y single letter. Here is the code to uild up grph of four-letter words. For it, you ll need to find list of words with one word per line. There re mny such lists online. # determine if two words differ y letter def one_wy(s, t): if len(s)!= len(t): return Flse count = 0 for i in rnge(len(s)): if s[i]!= t[i]: count += return count== G = Grph() words = [line.strip() for line in open('wordlist.txt')

29 CHAPTER. PROOFS, CONSTRUCTIONS, ALGORITHMS, AND APPLICATIONS 9 # dd vertices for word in words: G.dd(word) if len(line.strip()) == 4] # loop over ll pirs of vertices nd dd edges when pproprite for word in words: for word in words: if one_wy(word, word): G.dd_edge(word, word) The code ove is not the most efficient pproch to uilding the grph, ut here we hve imed for simplicity, not speed. Finding word ldder is now s simple s looking for shortest pth etween two vertices. It is lso interesting to look t the components of this grph. The list of words I used hd 68 four-letter words. The grph hs 0 components. One of those components is 485 words long, indicting tht there is word ldder possile etween most four-letter words. Of the other components, 8 of them hd just one word. Words in these components include void, hymn, ends, nd onyx. The remining components contin etween nd 6 words, the lrgest of which contins the words chy, che, shy, cme, cne, nd cre. Rel pplictions The pplictions presented here re of more of fun thn prcticl nture, ut don t let tht fool you. Grph theory is pplied to rel prolems in mny fields. Here is very smll smple: isomer prolems in chemistry, DNA sequencing prolems, flood fill in computer grphics, nd mtching orgn donors to recipients. There re lso mny networking exmples such s rel nd simulted neurl networks, socil networks, pcket routing on the internet, where to locte we servers on CDN, spred of disese, nd network models of virl mrketing.

30 Chpter Biprtite Grphs nd Trees. Biprtite grphs Shown elow re few iprtite grphs. Notice tht the vertices re roken into two prts top prt nd ottom prt. Edges re only possile etween the two prts, not within prt, with the top nd ottom prts oth eing independent sets. Here is the forml definition of iprtite grph: Definition 8. A iprtite grph is grph whose vertex set cn e written s the union of two disjoint sets X nd Y, clled prtite sets, such tht every edge of the grph hs one endpoint in X nd the other in Y. In short, in iprtite grph, it is possile to rek the vertices into two prts, with edges only going etween the prts, never inside of one. We typiclly drw iprtite grphs with the X prtite set on top nd the Y prtite set on the ottom, like in the exmples ove. However, mny grphs tht re not typiclly drwn this wy re iprtite. For exmple, grids re iprtite, s cn e seen in the exmple elow. c d e f X Y X Y X Y c e g i X g h i X Y X d f h Y How to tell if grph is iprtite The pproch to telling if grph is iprtite is this: Strt t ny vertex nd lel it with n X. Lel ech of its neighors with Y. Lel ech of their neighors with n X. Keep doing this, visiting ech vertex in the grph, leling its neighors with the opposite of its own lel. If it ever hppens tht two djcent vertices get the sme lel or tht some vertex ends up leled with oth n X nd Y, then the grph is not iprtite. If we get through every vertex without this hppening, then the grph is iprtite, with the vertices leled X nd the vertices leled Y forming the two prts of the iprtition. An exmple is shown elow, strting t the middle vertex. 0

31 CHAPTER. BIPARTITE GRAPHS AND TREES Y X Y X X Y X Y Y X Y Y X Y X This cn e coded using the BFS/DFS code from the lst chpter to visit the vertices. Suppose we try the lgorithm on the tringle K. We strt y leling the top vertex with n X. Then its two neighors get leled with Y, nd we hve prolem ecuse they re djcent. A similr prolem hppens with C 5. See elow. X Y X Y Y Y X X In fct, ny odd cycle suffers from this prolem, mening tht no odd cycle cn e iprtite. So iprtite grphs cn t hve odd cycles. Wht is remrkle is tht odd cycles re the only thing iprtite grphs cn t hve. Nmely, ny grph without ny odd cycles must e iprtite. Theorem 7. A grph is iprtite if nd only if it hs no odd cycles. Proof. First, if grph is iprtite, ny cycle must hve n even length. To see this, strt y ssuming the two prtite sets re nmed X nd Y. Pick ny cycle in the grph. As we trce from vertex to vertex long tht cycle, we lternte etween vertices of X nd vertices of Y. Suppose we strt trcing t vertex of X. Then the second, fourth, sixth, etc. vertices we meet re in X nd the others re in Y. Thus when we return to our strting vertex, we hve gone n even numer of steps, mening the cycle hs n even length. See the figure elow for n exmple. The lels indicte the order in which we trce round the cycle. X 0,6 4 Y 5 Now suppose we hve grph with no odd cycles. Pick ny component of the grph nd pick ny vertex in tht component. Let X e ll the vertices in the component t n even distnce from nd let Y e ll the vertices in the component t n odd distnce from. We clim this forms iprtition of the component. To show this, it suffices to show there re no edges within X or within Y. Suppose there were such n edge etween vertices u nd v, with oth in X or oth in Y. So u nd v re oth either t n even distnce from or oth t n odd distnce from. Recll tht the distnce etween vertices is the length of the shortest pth etween them. Consider the shortest pths from to u nd from to v. Let e the lst vertex those pths hve in common (which might possily just e itself). The pth from to u followed y edge uv, followed y the pth from v to forms cycle. Its length is plus the distnce from to u plus the distnce from to v, nd this must e odd since the distnces from to u nd from to v must oth e odd or oth e even, mening their sum is even. This is contrdiction, so there cnnot e ny edge within X or within Y. Thus X nd Y form iprtition of the component. We cn do this sme process for every component to get iprtition of the entire grph.

32 CHAPTER. BIPARTITE GRAPHS AND TREES The picture elow shows n exmple of the odd cycle creted in the second prt of the proof. u v The second prt of the proof relies on clever ide, tht of picking vertex nd reking the grph into two groups: vertices tht re n even distnce from it nd vertices tht re n odd distnce from it. If you wnt to rememer how the proof goes, just rememer tht key ide, nd the rest consists of little work to mke sure tht the ide works. Mny theorems in grph theory (nd mth in generl) re like this, where there is one ig ide tht the proof revolves round. Lern tht ide nd you cn often work out the other smll detils to complete the proof. Reltionship etween the lgorithm nd the theorem Usully when there is nice chrcteriztion of something in grph theory like this, there is simple lgorithm tht goes long with it. Tht is the cse here. Though we won t do it here, it s not too hrd to dpt the proof ove to show tht the lgorithm of the previous section correctly tells if grph is iprtite. More on iprtite grphs Biprtite grphs hve numer of pplictions, some of which we will see lter. A prticulrly importnt clss of iprtite grphs re complete iprtite grphs. These re iprtite grphs with ll possile edges etween the two prts. The nottion K m,n denotes complete iprtite grph with one prt of m vertices nd the other of n vertices. A few exmples re shown elow. Biprtite grphs re specil cse of multiprtite grphs, where insted of two prtite sets there cn e severl. For instnce, shown elow is complete multiprtite grph with four prts.. Trees Trees re grphs tht hve vriety of importnt pplictions in mth nd especilly computer science. Shown elow re few trees.

33 CHAPTER. BIPARTITE GRAPHS AND TREES Trees hve certin tree-like rnching to them, which is where they get their nme. It is little tricky to define tree in terms of this rnching ide. A simpler definition is the following: Definition 9. A tree is connected grph with no cycles. In turns out tht eing connected nd hving no cycles is enough to give trees vriety of useful properties. For instnce, we hve the following: In ny tree, there is exctly one pth from every vertex to every other vertex. Trees hve the lest numer of edges grph cn hve nd still e connected. In prticulr, every edge of tree is cut edge. Trees hve the most numer of edges grph cn hve without hving cycle. In prticulr, dding ny edge to tree cretes exctly one cycle. Every tree with n vertices hs exctly n edges. We won t formlly prove these, ut here re few resons why they re true: Regrding the first property, if there were two pths to vertex, then we could comine them to get cycle. Regrding the second property, recll tht Theorem 6 sys cut edges re precisely those edges tht don t lie on cycle. For the third property, if you dd n edge etween vertices u nd v, tht would crete cycle involving edge uv nd the pth tht is gurnteed to exist etween u nd v. Leves nd induction The lst property of the previous section provides nice opportunity to use induction. But first, we need the following definition nd theorem. Definition 0. A lef in tree is vertex of degree. Tht is, leves re the vertices tht re t the ends of tree. A lef hs only one neighor. And every nontrivil tree hs lef, s stted elow. Theorem 8. Every tree with t lest two vertices hs t lest two leves. Proof. Consider ny pth of mximum length in the tree. Becuse the tree hs t lest two vertices nd is connected, this pth must exist. Both of the endpoints of tht pth re of degree in the tree, with their only neighors eing the vertices immeditely efore them on the pth. They cn hve no other neighors on the pth since tht would crete cycle, which is impossile in tree. And they cn hve no other neighor outside of the pth since then we could hve used such neighor to extend the pth, which is impossile s the pth is lredy mximum length. We will use this fct nd induction now to prove tht every tree with n vertices hs exctly n edges. The se cse of tree on one vertex with no edges fits the property. Now ssume tht ll trees on n vertices contin n edges. Let T e tree on n+ vertices. By Theorem 8, T hs lef v. The grph T v hs n vertices

34 CHAPTER. BIPARTITE GRAPHS AND TREES 4 nd is tree since removing vertex cnnot crete cycle, nd removing lef cnnot disconnect the grph. So y the induction hypothesis, T v hs n edges. Since one edge ws removed from T to get T v, T must hve n edges. Thus the result is true y induction. This technique of pulling off lef in n induction proof is useful in proofs involving trees. Alternte definitions of trees Any of the tree properties mentioned erlier cn themselves e used to reformulte the definition of tree. Theorem 9. The following re equivlent for grph T:. T is tree.. Every pir of vertices of T is connected y exctly one pth.. T is connected nd removing ny edge disconnects it. 4. T hs no cycles nd dding ny edge cretes cycle. 5. T is connected grph with n vertices nd n edges. 6. T is n cyclic grph with n vertices nd n edges. The proof of ny prt of this is not difficult nd involves rguments similr to those we gve ove. In ddition to these, there re other wys to comine tree properties to get lternte chrcteriztions of trees. Forests If we remove connectedness from the definition of tree, then we hve wht is clled forest. Definition. A forest is grph with no cycles. So, techniclly, tree is lso forest, ut most of the time, we think of forest s grph consisting of severl components, ll of which re trees (s you might expect from the nme forest). A forest is shown elow. More out trees Trees nd forests re iprtite. By definition, they hve no cycles, so they hve no odd cycles, mking them iprtite y Theorem 7. Trees hve innumerle pplictions, especilly in computer science. There, rooted trees re the focus. These re trees where one vertex is designted s the root nd the tree grows outwrd from there. With root it mkes sense to think of vertices s eing prents of other other vertices, sort of like in fmily tree. Of prticulr interest re inry trees, where ech vertex hs t most two children. Binry trees re importnt in mny lgorithms of computer science, such s serching, sorting, nd expression prsing.

35 CHAPTER. BIPARTITE GRAPHS AND TREES 5. Spnning trees A prolem tht comes up often is to find connected sugrph of grph tht uses s few edges s possile. Essentilly, we wnt to e le to get from ny vertex to ny other, nd we wnt to use s few edges s we cn to mke this possile. Hving cycle in the sugrph would men we hve redundnt edge, so we don t wnt ny cycles. Thus we re looking for connected sugrph with no cycles tht includes every vertex of the originl grph. Such grph is clled spnning tree. Shown elow re two grphs with spnning trees highlighted. Spnning trees hve numer of pplictions. A nice exmple shows up in computer network pcket routing. Here we hve unch of computers networked together. Represented s grph, the computers ecome vertices nd direct connections etween two computers correspond to edges. When one computer wnts to send pcket of informtion to nother, tht pcket is trnsferred etween computers on the network until it gets to its destintion, in process clled routing. Cycles in tht network cn cuse pcket to ounce round forever. So the computers ech run n lgorithm designed to find spnning tree tht is, sugrph of the network tht hs no cycles yet still mkes it possile to get from ny computer to ny other computer. A nice wy to find spnning tree in grph uses smll vrition of the DFS/BFS lgorithms we sw erlier. We uild up the tree s follows: The first time we see vertex, we dd it to the tree long with the edge to it from the current vertex eing serched. If we see the vertex gin when serching from nother vertex, we don t dd the edge tht time. Essentilly, we wlk through the grph nd dd edges tht don t cuse cycles until we hve reched every vertex. An lternte pproch would e to remove edges from the grph until there re no cycles left, mking sure to keep the grph connected t ll times. Counting spnning trees Mthemticins like to count things, nd spnning trees re no exception, especilly s there is some interesting mth involved. In this section, we will use the nottion τ(g) to denote the numer of spnning trees of grph G. One simple fct is tht if T is tree, then τ(t) =. Another reltively simple fct is tht τ(c n ) = n. This comes from the fct tht leving off ny one of the n edges of cycle cretes different spnning tree, nd removing ny more thn one edge would not leve tree. One other fct is tht if grph hs cut vertex, like in the grph elow, then the cut vertex essentilly seprtes the grph into two prts, nd the spnning trees of the two prts will hve no interction except through tht cut vertex. So we cn get the totl numer of spnning trees y multiplying the numers of spnning trees on either side of the cut vertex, giving 4 = in totl. One formul for the numer of spnning trees relies on something clled the contrction of n edge. Contrction is where we essentilly contrct or pinch n edge down to single point, where the edge is removed nd its two

36 CHAPTER. BIPARTITE GRAPHS AND TREES 6 endpoints re reduced to single vertex. Two exmples re shown elow, where the edge e = uv is contrcted into new vertex w. u e v Here is the forml definition: w u G G e G G e Definition. Suppose G is grph with n edge e = uv. Then the contrction of e in G is n opertion tht cretes new grph, denoted G e, tht hs the sme vertices nd edges s G except u nd v re replced y new vertex w which is djcent to ll of the neighors of u nd v in G nd nothing else. Using this, we get the following formul for the numer of spnning trees of grph G: τ(g) = τ(g e) + τ(g e). Why does this work? First, the spnning trees of G e re essentilly the sme s the spnning trees of G tht don t include e. Second T(G e) counts the spnning trees of G tht do contin e. This is ecuse ny such spnning tree hs to include the new doule-vertex of G e, which corresponds to including edge e in the originl, since the new doule-vertex stnds in plce of e nd its two endpoints. Here is n exmple. We will compute the numer of spnning trees of G = P P s shown elow. e v w e G G e G e Tking the middle edge e out of G leves us with C 6. Any 5 edges of C 6 (siclly leving out just one edge) mke spnning tree of C 6, so there re 6 spnning trees of C 6. Contrcting the middle edge e of G leves us with the owtie grph shown ove. Any spnning tree must include edges from the left hlf of the grph nd from the right. There re wys to include edges on the left nd wys to include on the right, so there re 9 possile spnning trees. So in totl in G, we hve τ(g) = = 5. In generl, this spnning tree formul cn e recursively pplied. Tht is, we rek G into G e nd G e nd then rek ech of those up further nd so on until we get to grphs whose spnning trees we cn esily count. For relly lrge grphs, this would get out of hnd quickly, s the numer of grphs to look t grows exponentilly. Prüfer Codes In this section, we will count the spnning trees of the complete grph K n. This is the sme s the numer of wys to connect up n items into tree. There is nice technique for this, clled Prüfer codes. We strt with tree with vertices leled through n. The key step of the Prüfer code process is this: Tke the smllest numered lef, remove it, nd record the numer of its neighor. Repet this step until there re just two vertices left. The result is n (n )-tuple of integers. An exmple of the process is shown elow

37 CHAPTER. BIPARTITE GRAPHS AND TREES 7 ( (, (,, (,,4,5 (,,4,5,6 (,,4,5,6,5 (,,4,5,6,5,8) Notice tht, t ech step, the vertex we remove is the one tht hs the smllest lel. We don t record its lel in the sequence; insted we record the lel of its neighor. This is wht llows us to reconstruct the tree from its sequence. To do this reconstruction, we do the following: Let P denote the Prüfer sequence, let V denote the sequence of integers from to n, representing the n vertices of the grph. Note tht V will lwys e two elements longer thn P. Here is the key step of the reconstruction process: Choose the smllest integer v of V tht is not in P, nd choose the first integer p of P. Add n edge etween vertices v nd p, nd remove v nd p from their corresponding sequences. Repet this step until P is empty. At this point, there will e two integers left in V. Add n edge etween their corresponding vertices. An exmple is shown elow, reversing the process of the previous exmple P (,,4,5,6,5,8) (,4,5,6,5,8) (4,5,6,5,8) (5,6,5,8) V (,,,4,5,6,7,8,9) (,,4,5,6,7,8,9) (,4,5,6,7,8,9) (4,5,6,7,8,9) P (6,5,8) (5,8) (8) ( ) V (5,6,7,8,9) (5,6,8,9) (5,8,9) (8,9) At ech step, we tke the first thing in P nd the smllest thing in V tht is not in P. So we won t lwys e tking the first thing in V. The Prüfer encoding nd decoding processes re inverses of ech other. There is little work tht goes into showing this, ut we will omit it here. We end up getting one-to-one correspondence etween leled trees nd Prüfer codes. Now ech Prüfer code hs n entries, ech of which cn e ny integer from through n, so there re n n possile Prüfer codes nd hence tht mny leled trees on n vertices. Ech of these leled trees is equivlent to spnning trees on K n, so we hve τ(k n ) = n n. This result is known s Cyley s theorem.

38 CHAPTER. BIPARTITE GRAPHS AND TREES 8 The Mtrix Tree Theorem For those who hve seen liner lger, there is nice technique using mtrices to count spnning trees. We strt with the djcency mtrix of the grph nd replce ll entries with their negtives. Then replce ll the entries long the digonl with the degrees of the vertices tht correspond to tht loction in the mtrix. Then delete ny row nd column nd tke the determinnt. The solute vlue of the determinnt gives the numer of spnning trees of the grph. This remrkle result is clled the Mtrix Tree Theorem. For exmple, shown elow is grph, followed y its djcency mtrix modified s mentioned ove, followed ythe mtrix otined y removing the first row nd column. Tking the determinnt of tht mtrix gives 5, which is the numer of spnning trees in the grph. c d e f c d e f c d e 0 0 f Non-isomorphic spnning trees When we count spnning trees, some of the spnning trees re likely isomorphic to others. For instnce, we know tht τ(c 6 ) is 6, ut ech of those six spnning trees is isomorphic to ll of the others, since they re ll copies of P 6. A much hrder question to nswer is how mny isomorphism clsses of spnning trees re there. For C 6, the nswer is, ut the nswer is not known for grphs in generl..4 Minimum spnning trees A weighted grph is grph where we lel ech edge with numer, clled its weight, like shown elow Weighted grphs re useful for modeling mny prolems. The weight often represents the cost of using tht edge. For exmple, the grph ove might represent rod network, where the vertices re cities nd the edges re rods tht cn e uilt etween the cities. The weights could represent the cost of uilding those rods. Continuing with this, suppose we wnt to uild just enough rods to mke it possile to get from ny city to ny other, nd we wnt to do so s cheply s possile. Here is the nswer for the grph ove: When solving this prolem, since we re trying to do things s cheply s possile, we don t wnt ny cycles, s tht would men we hve redundnt edge. And we wnt to e le to get to ny vertex in the grph, so wht we wnt is minimum spnning tree, spnning tree where the sum of ll the edge weights in the tree is s smll s possile. There re severl lgorithms for finding minimum spnning trees. We will look t two: Kruskl s lgorithm nd Prim s lgorithm.

39 CHAPTER. BIPARTITE GRAPHS AND TREES 9 Kruskl s lgorithm Kruskl s lgorithm uilds up spnning tree of grph G one edge t time. The key ide is this: At ech step of the lgorithm, we tke the edge of G with the smllest weight such tht dding tht edge into the tree eing uilt does not crete cycle. We cn rek edge-weight ties however we wnt. We continue dding edges ccording to the rule ove until it is no longer possile. In grph with n vertices, we will lwys need to dd exctly n edges. An exmple is shown elow. Edges re highlighted in the order they re dded Kruskl s lgorithm is n exmple of greedy lgorithm. It is clled tht ecuse t ech step it chooses the chepest ville edge without thinking out the future consequences of tht choice. It is remrkle tht this strtegy will lwys give minimum spnning tree. It s worth tlking out why Kruskl s lgorithm works. We should e sure tht the grph T tht it uilds is ctully spnning tree of the grph. First, T clerly hs no cycles ecuse Kruskl s Algorithm y definition cn t crete one. Next, T is connected, since if it weren t, we could dd n edge etween components of T without cusing cycle. Finlly, T is spnning (includes every vertex), since if it weren t, we could dd n edge from T to vertex not in T without cusing cycle. We know tht trees on n vertices lwys hve n edges, so we will need to dd exctly n edges. Now let s consider why Kruskl s tree T hs minimum weight. Consider some minimum spnning tree S tht is not equl to T. As we go through the Kruskl s process nd dd edges, eventully we dd n edge e to T tht is not prt of S. Suppose we try to dd e to S. Tht would crete cycle y the sic properties of trees. Along tht cycle there must e some other edge d tht is not in T ecuse T is tree nd it cn t contin every edge of tht cycle. See elow where hypotheticl portion of S is shown long with d nd e.

40 CHAPTER. BIPARTITE GRAPHS AND TREES 40 d e Consider removing d from S nd replcing it with e (this is the tree S d + e). Becuse we re just exchnging one cycle edge for nother, S d + e is still spnning tree of G. Now, when the Kruskl s process dded edge e, edge d ws ville to e dded (nd wouldn t hve cused cycle), ut Kruskl s chose e. Tht mens the weight of e is less thn or equl to the weight of d. This mkes S d + e is minimum spnning tree of G tht grees with T on one more edge thn S does. We cn repet this process gin nd gin until we get minimum spnning tree tht grees with T on every edge, mening tht T must e minimum spnning tree. It s not too hrd to write some code implementing Kruskl s lgorithm, though we won t do so here. The trickiest prt is checking to see if dding n edge cretes cycle. Something clled the disjoint set dt structure provides nice wy to do this. Prim s Algorithm Prim s Algorithm is nother pproch to finding minimum spnning tree. It is greedy, like Kruskl s, ut it differs in how it chooses its edges. Here is how it works: We pick ny vertex to strt from nd choose the chepest edge incident on tht vertex. The tree we re uilding now hs two vertices. Look t ll the edges from these two vertices to other vertices, nd pick the chepest one. We hve now dded three vertices to our tree. Keep this process up, lwys following the following key rule: Add the chepest edge from vertex lredy dded to one not yet reched. Just like Kruskl s, we cn rek edge-weight ties however we like. We stop the lgorithm once every vertex hs een dded to the tree. Here is n exmple. We will strt uilding the tree from the upper left

41 CHAPTER. BIPARTITE GRAPHS AND TREES 4 We see tht the grph tht Prim s lgorithm uilds up is tree t every step. This is different from the grph produced y Kruskl s which is disconnected up until the finl step. It s interesting to note tht Prim s lgorithm will not necessrily produce the sme tree s Kruskl s. If the edge weights re ll different, then the two lgorithms will produce the sme tree, ut if the edge weights re not ll different, then there my e multiple minimum spnning trees, nd the two lgorithms my find different ones. Though we won t do so, we cn show tht Prim s Algorithm works in similr wy to how we did it for Kruskl s. A note out greedy lgorithms We referred to Kruskl s nd Prim s lgorithms s greedy lgorithms. A greedy lgorithm t ech step lwys chooses the option tht looks the est t tht step, without consider the consequences of tht choice on future steps. For instnce, Kruskl s nd Prim s lgorithms lwys choose the chepest edge they cn. This type of strtegy doesn t work for ll prolems. For instnce, it would e pretty d wy to ply chess, to only look t the current turn nd not consider its effect on future turns. However, greedy lgorithms do give the optiml solution to numer of prolems in grph theory, nd even when they don t, they often give resonly good solution quickly..5 Shortest pths In this section we will look t finding the chepest weighted pth etween two vertices. Often this is referred to s finding the shortest pth in grph. The most populr method for doing this is clled Dijkstr s Algorithm. To see how it works, consider the exmple elow in which we re looking for the shortest pth from vertex to vertex g. (, ) 4 (4, ) d 4 e 9 5 g (, ) 4 (, ) (4, ) d 4 (, ) e 9 5 g 9 (9, ) c 5 8 f 9 (9, ) c 5 8 f (, ) 9 (, ) d 4 (, ) e 9 5 (7, e) g (, ) 4 (, ) d 4 (, ) e 9 5 (7, e) g 9 (9, ) c 8 f 9 (8, d) (9, ) c 5 8 (5, d) f

42 CHAPTER. BIPARTITE GRAPHS AND TREES 4 (, ) 4 (, ) d 4 (, ) e 9 5 (6, f ) (7, e) g (, ) 4 (, ) d 4 (, ) e 9 5 (6, f ) g 9 (8, d) c 5 8 (5, d) f 9 (8, d) c 5 8 (5, d) f We strt from vertex, visiting ech of its neighors nd leling them with the cost from, long with n to indicte tht we found them vi vertex. We then mrk s serched mening we will not visit it ny more. We next pick the neighor of tht ws leled with the smllest cost nd visit its neighors. This is vertex. Currently, we know tht we cn get to from with totl cost of. Since it costs to get from to e, we lel e s (, ) indicting tht we cn get from to e for totl cost of with indicting tht we got to e vi vertex. Similrly, we cn get to vertex d with totl cost of y going through. Tht vertex d hs lredy een leled, ut our route through is cheper, so we will replce the lel on d with (, ). If the cost to d through hd een more expensive, we would not chnge the lel on d. Also, we ignore the edge from ck to since hs een mrked s serched. And now tht we re done with, we mrk it s serched. We continue this process for the other vertices in the grph. We lwys choose the next vertex to visit y looking t ll the vertices in the grph tht hve een leled ut not mrked s visited, nd choose the one tht hs een leled with the chepest totl cost, reking ties ritrrily. The next vertex to visit would e e, s its totl cost is currently, cheper thn ny other leled vertex. After few more steps we get to the point tht g is the chepest leled vertex. This is our stopping point. Once our gol vertex hs the chepest lel, no other route to tht gol could possily e etter thn wht we hve. So we stop there, even though we hven t necessrily explored ll possile routes to the gol. We then use the lels to trce the pth ckwrd to the strt. For instnce, t the end g ws leled with (6, f ), so we trce ckwrd from g to f. Tht vertex f ws leled with (5, d), so we trce ckwrd to d nd from there ck to nd then, giving us the pth d f g with totl length of 6 s the shortest pth. Algorithm description Here is short description of the lgorithm in generl. Assume the strt vertex is clled. The lgorithm lels vertex v with two things cost nd vertex. The cost is the current shortest known distnce from, nd the vertex is the neighor of v on the pth from to v tht gives tht shortest known distnce. The lgorithm continully improves the cost s it finds etter pths to v. Here re the steps of the lgorithm.. Strt y setting the cost lel of ech neighor of to the cost of the edge from to it, nd set its vertex lel to. Mrk s serched. We will not visit it gin.. Then pick the lelled vertex v tht hs the smllest cost, reking ties however we wnt. Look t ech neighor of v. If the neighor is unleled, then we lel it with cost of c plus the weight of the edge to it from v. Its vertex lel ecomes v. If the neighor is lredy leled, we compre its current cost lel with c plus the weight of the edge to it the neighor from v. If this is no etter thn the neighor s current cost lel, then we do nothing more with this vertex. Otherwise, we updte the lel s cost with this new cost nd updte the neighor s vertex lel to v. We repet this for every unserched neighor of v nd then lel v itself s serched, mening we will not visit it gin.. The lgorithm continues this wy, t ech step picking the unserched lelled vertex tht hs the smllest cost nd updting its neighors lels s in Step. 4. The lgorithm ends when the lelled vertex with the smllest cost is the destintion vertex. Tht cost is the totl cost of the shortest pth. We then use the vertex lels to trce ck to find the pth from the

43 CHAPTER. BIPARTITE GRAPHS AND TREES 4 strt to the destintion. The destintion vertex s vertex lel is the second-to-lst vertex on the pth. Tht vertex s vertex lel is the third-to-lst vertex on the pth, etc. Dijkstr s lgorithm is quite fmous nd is used in numer of rel pplictions, such s network pcket routing.

44 Chpter 4 Eulerin nd Hmiltonin grphs This chpter is out two types of round trips through grph. The first, clled n Eulerin circuit, is round trip through grph visiting every edge exctly once; the second, clled Hmiltonin cycle, is round trip visiting every vertex exctly once. Eulerin circuits turn out to e esy to check for, while Hmiltonin cycles re not. 4. Eulerin circuits Trditionlly, the first prolem in grph theory is considered to e the Brides of Königserg prolem. A sketch of the city of Königserg nd its seven ridges is shown elow on the left. In the erly 700s, some residents wondered if it would e possile to tke round trip through the city tht crossed ech ridge exctly once. The myor sent letter sking out the prolem to the fmous mthemticin Leonhrd Euler, who solved the prolem y representing it s grph, essentilly inventing the field of grph theory. Euler represented ech of the four lnd regions with grph, with the ridges corresponding to edges, s shown ove on the right. We cn see how the grph retins only the most importnt informtion from the mp, nmely which regions re connected to which other regions vi ridges. The exct detils of the regions shpes re not importnt. By looking t the degrees of the vertices, Euler determined tht the desired trip ws impossile. The key is the vertices of degree. If you strt t one of those vertices, you will need to use one of its incident edges to leve tht vertex. At some point lter, you will use nother of its incident edges to rrive ck t the vertex nd then use the lst incident edge to leve the vertex, mking it impossile to return to it (rememer tht we wnt to finish where we strt). If one of those vertices of degree is not the strting point, similr rgument holds, this time leving us stuck t tht vertex with no wy to leve fter our second visit to tht vertex. We cn sk similr question of ny grph: is it possile to wlk through the grph, using every edge exctly once nd ending up t the strt? Such trip through grph is nmed for Euler. Definition. An Eulerin circuit (or Eulerin tour) in grph is n lternting sequence of vertices nd edges in 44

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs. Lecture 5 Wlks, Trils, Pths nd Connectedness Reding: Some of the mteril in this lecture comes from Section 1.2 of Dieter Jungnickel (2008), Grphs, Networks nd Algorithms, 3rd edition, which is ville online

More information

COMP 423 lecture 11 Jan. 28, 2008

COMP 423 lecture 11 Jan. 28, 2008 COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring

More information

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig CS311H: Discrete Mthemtics Grph Theory IV Instructor: Işıl Dillig Instructor: Işıl Dillig, CS311H: Discrete Mthemtics Grph Theory IV 1/25 A Non-plnr Grph Regions of Plnr Grph The plnr representtion of

More information

Ma/CS 6b Class 1: Graph Recap

Ma/CS 6b Class 1: Graph Recap M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Adm Sheffer. Office hour: Tuesdys 4pm. dmsh@cltech.edu TA: Victor Kstkin. Office hour: Tuesdys 7pm. 1:00 Mondy, Wednesdy, nd Fridy. http://www.mth.cltech.edu/~2014-15/2term/m006/

More information

2 Computing all Intersections of a Set of Segments Line Segment Intersection

2 Computing all Intersections of a Set of Segments Line Segment Intersection 15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design

More information

Ma/CS 6b Class 1: Graph Recap

Ma/CS 6b Class 1: Graph Recap M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Instructor: Adm Sheffer. TA: Cosmin Pohot. 1pm Mondys, Wednesdys, nd Fridys. http://mth.cltech.edu/~2015-16/2term/m006/ Min ook: Introduction to Grph

More information

Fig.25: the Role of LEX

Fig.25: the Role of LEX The Lnguge for Specifying Lexicl Anlyzer We shll now study how to uild lexicl nlyzer from specifiction of tokens in the form of list of regulr expressions The discussion centers round the design of n existing

More information

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

In the last lecture, we discussed how valid tokens may be specified by regular expressions. LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.

More information

10.5 Graphing Quadratic Functions

10.5 Graphing Quadratic Functions 0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions

More information

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis CS143 Hndout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexicl Anlysis In this first written ssignment, you'll get the chnce to ply round with the vrious constructions tht come up when doing lexicl

More information

Graphs with at most two trees in a forest building process

Graphs with at most two trees in a forest building process Grphs with t most two trees in forest uilding process rxiv:802.0533v [mth.co] 4 Fe 208 Steve Butler Mis Hmnk Mrie Hrdt Astrct Given grph, we cn form spnning forest y first sorting the edges in some order,

More information

What are suffix trees?

What are suffix trees? Suffix Trees 1 Wht re suffix trees? Allow lgorithm designers to store very lrge mount of informtion out strings while still keeping within liner spce Allow users to serch for new strings in the originl

More information

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011 CSCI 3130: Forml Lnguges nd utomt Theory Lecture 12 The Chinese University of Hong Kong, Fll 2011 ndrej Bogdnov In progrmming lnguges, uilding prse trees is significnt tsk ecuse prse trees tell us the

More information

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries Tries Yufei To KAIST April 9, 2013 Y. To, April 9, 2013 Tries In this lecture, we will discuss the following exct mtching prolem on strings. Prolem Let S e set of strings, ech of which hs unique integer

More information

Dr. D.M. Akbar Hussain

Dr. D.M. Akbar Hussain Dr. D.M. Akr Hussin Lexicl Anlysis. Bsic Ide: Red the source code nd generte tokens, it is similr wht humns will do to red in; just tking on the input nd reking it down in pieces. Ech token is sequence

More information

Section 3.1: Sequences and Series

Section 3.1: Sequences and Series Section.: Sequences d Series Sequences Let s strt out with the definition of sequence: sequence: ordered list of numbers, often with definite pttern Recll tht in set, order doesn t mtter so this is one

More information

A dual of the rectangle-segmentation problem for binary matrices

A dual of the rectangle-segmentation problem for binary matrices A dul of the rectngle-segmenttion prolem for inry mtrices Thoms Klinowski Astrct We consider the prolem to decompose inry mtrix into smll numer of inry mtrices whose -entries form rectngle. We show tht

More information

MATH 25 CLASS 5 NOTES, SEP

MATH 25 CLASS 5 NOTES, SEP MATH 25 CLASS 5 NOTES, SEP 30 2011 Contents 1. A brief diversion: reltively prime numbers 1 2. Lest common multiples 3 3. Finding ll solutions to x + by = c 4 Quick links to definitions/theorems Euclid

More information

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus Unit #9 : Definite Integrl Properties, Fundmentl Theorem of Clculus Gols: Identify properties of definite integrls Define odd nd even functions, nd reltionship to integrl vlues Introduce the Fundmentl

More information

Definition of Regular Expression

Definition of Regular Expression Definition of Regulr Expression After the definition of the string nd lnguges, we re redy to descrie regulr expressions, the nottion we shll use to define the clss of lnguges known s regulr sets. Recll

More information

INTRODUCTION TO SIMPLICIAL COMPLEXES

INTRODUCTION TO SIMPLICIAL COMPLEXES INTRODUCTION TO SIMPLICIAL COMPLEXES CASEY KELLEHER AND ALESSANDRA PANTANO 0.1. Introduction. In this ctivity set we re going to introduce notion from Algebric Topology clled simplicil homology. The min

More information

6.3 Volumes. Just as area is always positive, so is volume and our attitudes towards finding it.

6.3 Volumes. Just as area is always positive, so is volume and our attitudes towards finding it. 6.3 Volumes Just s re is lwys positive, so is volume nd our ttitudes towrds finding it. Let s review how to find the volume of regulr geometric prism, tht is, 3-dimensionl oject with two regulr fces seprted

More information

Slides for Data Mining by I. H. Witten and E. Frank

Slides for Data Mining by I. H. Witten and E. Frank Slides for Dt Mining y I. H. Witten nd E. Frnk Simplicity first Simple lgorithms often work very well! There re mny kinds of simple structure, eg: One ttriute does ll the work All ttriutes contriute eqully

More information

MTH 146 Conics Supplement

MTH 146 Conics Supplement 105- Review of Conics MTH 146 Conics Supplement In this section we review conics If ou ne more detils thn re present in the notes, r through section 105 of the ook Definition: A prol is the set of points

More information

Section 10.4 Hyperbolas

Section 10.4 Hyperbolas 66 Section 10.4 Hyperbols Objective : Definition of hyperbol & hyperbols centered t (0, 0). The third type of conic we will study is the hyperbol. It is defined in the sme mnner tht we defined the prbol

More information

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012 Fculty of Mthemtics Wterloo, Ontrio N2L 3G1 Grde 7/8 Mth Circles Geometric Arithmetic Octoer 31, 2012 Centre for Eduction in Mthemtics nd Computing Ancient Greece hs given irth to some of the most importnt

More information

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search. CS 88: Artificil Intelligence Fll 00 Lecture : A* Serch 9//00 A* Serch rph Serch Tody Heuristic Design Dn Klein UC Berkeley Multiple slides from Sturt Russell or Andrew Moore Recp: Serch Exmple: Pncke

More information

CS 241 Week 4 Tutorial Solutions

CS 241 Week 4 Tutorial Solutions CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it

More information

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016 Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl

More information

Chapter44. Polygons and solids. Contents: A Polygons B Triangles C Quadrilaterals D Solids E Constructing solids

Chapter44. Polygons and solids. Contents: A Polygons B Triangles C Quadrilaterals D Solids E Constructing solids Chpter44 Polygons nd solids Contents: A Polygons B Tringles C Qudrilterls D Solids E Constructing solids 74 POLYGONS AND SOLIDS (Chpter 4) Opening prolem Things to think out: c Wht different shpes cn you

More information

Typing with Weird Keyboards Notes

Typing with Weird Keyboards Notes Typing with Weird Keyords Notes Ykov Berchenko-Kogn August 25, 2012 Astrct Consider lnguge with n lphet consisting of just four letters,,,, nd. There is spelling rule tht sys tht whenever you see n next

More information

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards A Tutology Checker loosely relted to Stålmrck s Algorithm y Mrtin Richrds mr@cl.cm.c.uk http://www.cl.cm.c.uk/users/mr/ University Computer Lortory New Museum Site Pemroke Street Cmridge, CB2 3QG Mrtin

More information

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming Lecture 10 Evolutionry Computtion: Evolution strtegies nd genetic progrmming Evolution strtegies Genetic progrmming Summry Negnevitsky, Person Eduction, 2011 1 Evolution Strtegies Another pproch to simulting

More information

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem Announcements Project : erch It s live! Due 9/. trt erly nd sk questions. It s longer thn most! Need prtner? Come up fter clss or try Pizz ections: cn go to ny, ut hve priority in your own C 88: Artificil

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5 CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,

More information

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers? 1.1 TEXAS ESSENTIAL KNOWLEDGE AND SKILLS Prepring for 2A.6.K, 2A.7.I Intervl Nottion nd Set Nottion Essentil Question When is it convenient to use set-uilder nottion to represent set of numers? A collection

More information

F. R. K. Chung y. University ofpennsylvania. Philadelphia, Pennsylvania R. L. Graham. AT&T Labs - Research. March 2,1997.

F. R. K. Chung y. University ofpennsylvania. Philadelphia, Pennsylvania R. L. Graham. AT&T Labs - Research. March 2,1997. Forced convex n-gons in the plne F. R. K. Chung y University ofpennsylvni Phildelphi, Pennsylvni 19104 R. L. Grhm AT&T Ls - Reserch Murry Hill, New Jersey 07974 Mrch 2,1997 Astrct In seminl pper from 1935,

More information

CS201 Discussion 10 DRAWTREE + TRIES

CS201 Discussion 10 DRAWTREE + TRIES CS201 Discussion 10 DRAWTREE + TRIES DrwTree First instinct: recursion As very generic structure, we could tckle this problem s follows: drw(): Find the root drw(root) drw(root): Write the line for the

More information

Before We Begin. Introduction to Spatial Domain Filtering. Introduction to Digital Image Processing. Overview (1): Administrative Details (1):

Before We Begin. Introduction to Spatial Domain Filtering. Introduction to Digital Image Processing. Overview (1): Administrative Details (1): Overview (): Before We Begin Administrtive detils Review some questions to consider Winter 2006 Imge Enhncement in the Sptil Domin: Bsics of Sptil Filtering, Smoothing Sptil Filters, Order Sttistics Filters

More information

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork MA1008 Clculus nd Liner Algebr for Engineers Course Notes for Section B Stephen Wills Deprtment of Mthemtics University College Cork s.wills@ucc.ie http://euclid.ucc.ie/pges/stff/wills/teching/m1008/ma1008.html

More information

9 Graph Cutting Procedures

9 Graph Cutting Procedures 9 Grph Cutting Procedures Lst clss we begn looking t how to embed rbitrry metrics into distributions of trees, nd proved the following theorem due to Brtl (1996): Theorem 9.1 (Brtl (1996)) Given metric

More information

such that the S i cover S, or equivalently S

such that the S i cover S, or equivalently S MATH 55 Triple Integrls Fll 16 1. Definition Given solid in spce, prtition of consists of finite set of solis = { 1,, n } such tht the i cover, or equivlently n i. Furthermore, for ech i, intersects i

More information

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl component

More information

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES)

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES) Numbers nd Opertions, Algebr, nd Functions 45. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES) In sequence of terms involving eponentil growth, which the testing service lso clls geometric

More information

Theory of Computation CSE 105

Theory of Computation CSE 105 $ $ $ Theory of Computtion CSE 105 Regulr Lnguges Study Guide nd Homework I Homework I: Solutions to the following problems should be turned in clss on July 1, 1999. Instructions: Write your nswers clerly

More information

Lily Yen and Mogens Hansen

Lily Yen and Mogens Hansen SKOLID / SKOLID No. 8 Lily Yen nd Mogens Hnsen Skolid hs joined Mthemticl Myhem which is eing reformtted s stnd-lone mthemtics journl for high school students. Solutions to prolems tht ppered in the lst

More information

Answer Key Lesson 6: Workshop: Angles and Lines

Answer Key Lesson 6: Workshop: Angles and Lines nswer Key esson 6: tudent Guide ngles nd ines Questions 1 3 (G p. 406) 1. 120 ; 360 2. hey re the sme. 3. 360 Here re four different ptterns tht re used to mke quilts. Work with your group. se your Power

More information

Misrepresentation of Preferences

Misrepresentation of Preferences Misrepresenttion of Preferences Gicomo Bonnno Deprtment of Economics, University of Cliforni, Dvis, USA gfbonnno@ucdvis.edu Socil choice functions Arrow s theorem sys tht it is not possible to extrct from

More information

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications. 15-112 Fll 2018 Midterm 1 October 11, 2018 Nme: Andrew ID: Recittion Section: ˆ You my not use ny books, notes, extr pper, or electronic devices during this exm. There should be nothing on your desk or

More information

MATH 2530: WORKSHEET 7. x 2 y dz dy dx =

MATH 2530: WORKSHEET 7. x 2 y dz dy dx = MATH 253: WORKSHT 7 () Wrm-up: () Review: polr coordintes, integrls involving polr coordintes, triple Riemnn sums, triple integrls, the pplictions of triple integrls (especilly to volume), nd cylindricl

More information

12-B FRACTIONS AND DECIMALS

12-B FRACTIONS AND DECIMALS -B Frctions nd Decimls. () If ll four integers were negtive, their product would be positive, nd so could not equl one of them. If ll four integers were positive, their product would be much greter thn

More information

Pointwise convergence need not behave well with respect to standard properties such as continuity.

Pointwise convergence need not behave well with respect to standard properties such as continuity. Chpter 3 Uniform Convergence Lecture 9 Sequences of functions re of gret importnce in mny res of pure nd pplied mthemtics, nd their properties cn often be studied in the context of metric spces, s in Exmples

More information

Simplifying Algebra. Simplifying Algebra. Curriculum Ready.

Simplifying Algebra. Simplifying Algebra. Curriculum Ready. Simplifying Alger Curriculum Redy www.mthletics.com This ooklet is ll out turning complex prolems into something simple. You will e le to do something like this! ( 9- # + 4 ' ) ' ( 9- + 7-) ' ' Give this

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop

More information

1 Quad-Edge Construction Operators

1 Quad-Edge Construction Operators CS48: Computer Grphics Hndout # Geometric Modeling Originl Hndout #5 Stnford University Tuesdy, 8 December 99 Originl Lecture #5: 9 November 99 Topics: Mnipultions with Qud-Edge Dt Structures Scribe: Mike

More information

a < a+ x < a+2 x < < a+n x = b, n A i n f(x i ) x. i=1 i=1

a < a+ x < a+2 x < < a+n x = b, n A i n f(x i ) x. i=1 i=1 Mth 33 Volume Stewrt 5.2 Geometry of integrls. In this section, we will lern how to compute volumes using integrls defined by slice nlysis. First, we recll from Clculus I how to compute res. Given the

More information

The Math Learning Center PO Box 12929, Salem, Oregon Math Learning Center

The Math Learning Center PO Box 12929, Salem, Oregon Math Learning Center Resource Overview Quntile Mesure: Skill or Concept: 80Q Multiply two frctions or frction nd whole numer. (QT N ) Excerpted from: The Mth Lerning Center PO Box 99, Slem, Oregon 9709 099 www.mthlerningcenter.org

More information

EXPONENTIAL & POWER GRAPHS

EXPONENTIAL & POWER GRAPHS Eponentil & Power Grphs EXPONENTIAL & POWER GRAPHS www.mthletics.com.u Eponentil EXPONENTIAL & Power & Grphs POWER GRAPHS These re grphs which result from equtions tht re not liner or qudrtic. The eponentil

More information

6.2 Volumes of Revolution: The Disk Method

6.2 Volumes of Revolution: The Disk Method mth ppliction: volumes by disks: volume prt ii 6 6 Volumes of Revolution: The Disk Method One of the simplest pplictions of integrtion (Theorem 6) nd the ccumultion process is to determine so-clled volumes

More information

Algorithm Design (5) Text Search

Algorithm Design (5) Text Search Algorithm Design (5) Text Serch Tkshi Chikym School of Engineering The University of Tokyo Text Serch Find sustring tht mtches the given key string in text dt of lrge mount Key string: chr x[m] Text Dt:

More information

Midterm 2 Sample solution

Midterm 2 Sample solution Nme: Instructions Midterm 2 Smple solution CMSC 430 Introduction to Compilers Fll 2012 November 28, 2012 This exm contins 9 pges, including this one. Mke sure you hve ll the pges. Write your nme on the

More information

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers Mth Modeling Lecture 4: Lgrnge Multipliers Pge 4452 Mthemticl Modeling Lecture 4: Lgrnge Multipliers Lgrnge multipliers re high powered mthemticl technique to find the mximum nd minimum of multidimensionl

More information

ON THE DEHN COMPLEX OF VIRTUAL LINKS

ON THE DEHN COMPLEX OF VIRTUAL LINKS ON THE DEHN COMPLEX OF VIRTUAL LINKS RACHEL BYRD, JENS HARLANDER Astrct. A virtul link comes with vriety of link complements. This rticle is concerned with the Dehn spce, pseudo mnifold with oundry, nd

More information

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

Unit 5 Vocabulary. A function is a special relationship where each input has a single output. MODULE 3 Terms Definition Picture/Exmple/Nottion 1 Function Nottion Function nottion is n efficient nd effective wy to write functions of ll types. This nottion llows you to identify the input vlue with

More information

arxiv: v1 [math.co] 18 Sep 2015

arxiv: v1 [math.co] 18 Sep 2015 Improvements on the density o miml -plnr grphs rxiv:509.05548v [mth.co] 8 Sep 05 János Brát MTA-ELTE Geometric nd Algeric Comintorics Reserch Group rt@cs.elte.hu nd Géz Tóth Alréd Rényi Institute o Mthemtics,

More information

Mathematics Background

Mathematics Background For more roust techer experience, plese visit Techer Plce t mthdshord.com/cmp3 Mthemtics Bckground Extending Understnding of Two-Dimensionl Geometry In Grde 6, re nd perimeter were introduced to develop

More information

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley AI Adjcent Fields Philosophy: Logic, methods of resoning Mind s physicl system Foundtions of lerning, lnguge, rtionlity Mthemtics Forml representtion nd proof Algorithms, computtion, (un)decidility, (in)trctility

More information

a(e, x) = x. Diagrammatically, this is encoded as the following commutative diagrams / X

a(e, x) = x. Diagrammatically, this is encoded as the following commutative diagrams / X 4. Mon, Sept. 30 Lst time, we defined the quotient topology coming from continuous surjection q : X! Y. Recll tht q is quotient mp (nd Y hs the quotient topology) if V Y is open precisely when q (V ) X

More information

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012 Dynmic Progrmming Andres Klppenecker [prtilly bsed on slides by Prof. Welch] 1 Dynmic Progrmming Optiml substructure An optiml solution to the problem contins within it optiml solutions to subproblems.

More information

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search Uninformed Serch [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.] Tody Serch Problems Uninformed Serch Methods

More information

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. General Tree Search. Uniform Cost. Lecture 3: A* Search 9/4/2007

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. General Tree Search. Uniform Cost. Lecture 3: A* Search 9/4/2007 CS 88: Artificil Intelligence Fll 2007 Lecture : A* Serch 9/4/2007 Dn Klein UC Berkeley Mny slides over the course dpted from either Sturt Russell or Andrew Moore Announcements Sections: New section 06:

More information

arxiv:cs.cg/ v1 18 Oct 2005

arxiv:cs.cg/ v1 18 Oct 2005 A Pir of Trees without Simultneous Geometric Embedding in the Plne rxiv:cs.cg/0510053 v1 18 Oct 2005 Mrtin Kutz Mx-Plnck-Institut für Informtik, Srbrücken, Germny mkutz@mpi-inf.mpg.de October 19, 2005

More information

8.2 Areas in the Plane

8.2 Areas in the Plane 39 Chpter 8 Applictions of Definite Integrls 8. Ares in the Plne Wht ou will lern out... Are Between Curves Are Enclosed Intersecting Curves Boundries with Chnging Functions Integrting with Respect to

More information

Reducing a DFA to a Minimal DFA

Reducing a DFA to a Minimal DFA Lexicl Anlysis - Prt 4 Reducing DFA to Miniml DFA Input: DFA IN Assume DFA IN never gets stuck (dd ded stte if necessry) Output: DFA MIN An equivlent DFA with the minimum numer of sttes. Hrry H. Porter,

More information

10.2 Graph Terminology and Special Types of Graphs

10.2 Graph Terminology and Special Types of Graphs 10.2 Grph Terminology n Speil Types of Grphs Definition 1. Two verties u n v in n unirete grph G re lle jent (or neighors) in G iff u n v re enpoints of n ege e of G. Suh n ege e is lle inient with the

More information

Suffix trees, suffix arrays, BWT

Suffix trees, suffix arrays, BWT ALGORITHMES POUR LA BIO-INFORMATIQUE ET LA VISUALISATION COURS 3 Rluc Uricru Suffix trees, suffix rrys, BWT Bsed on: Suffix trees nd suffix rrys presenttion y Him Kpln Suffix trees course y Pco Gomez Liner-Time

More information

COMBINATORIAL PATTERN MATCHING

COMBINATORIAL PATTERN MATCHING COMBINATORIAL PATTERN MATCHING Genomic Repets Exmple of repets: ATGGTCTAGGTCCTAGTGGTC Motivtion to find them: Genomic rerrngements re often ssocited with repets Trce evolutionry secrets Mny tumors re chrcterized

More information

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam. 15-112 Spring 2018 Midterm Exm 1 Mrch 1, 2018 Nme: Andrew ID: Recittion Section: You my not use ny books, notes, or electronic devices during this exm. You my not sk questions bout the exm except for lnguge

More information

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association 9. CISC - Curriculum & Instruction Steering Committee The Winning EQUATION A HIGH QUALITY MATHEMATICS PROFESSIONAL DEVELOPMENT PROGRAM FOR TEACHERS IN GRADES THROUGH ALGEBRA II STRAND: NUMBER SENSE: Rtionl

More information

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table TDDD55 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing, Prt 2 Constructing Prse Tles Prse tle construction Grmmr conflict hndling Ctegories of LR Grmmrs nd Prsers Peter Fritzson, Christoph

More information

Integration. September 28, 2017

Integration. September 28, 2017 Integrtion September 8, 7 Introduction We hve lerned in previous chpter on how to do the differentition. It is conventionl in mthemtics tht we re supposed to lern bout the integrtion s well. As you my

More information

Intermediate Information Structures

Intermediate Information Structures CPSC 335 Intermedite Informtion Structures LECTURE 13 Suffix Trees Jon Rokne Computer Science University of Clgry Cnd Modified from CMSC 423 - Todd Trengen UMD upd Preprocessing Strings We will look t

More information

From Dependencies to Evaluation Strategies

From Dependencies to Evaluation Strategies From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute

More information

ZZ - Advanced Math Review 2017

ZZ - Advanced Math Review 2017 ZZ - Advnced Mth Review Mtrix Multipliction Given! nd! find the sum of the elements of the product BA First, rewrite the mtrices in the correct order to multiply The product is BA hs order x since B is

More information

Summer Review Packet For Algebra 2 CP/Honors

Summer Review Packet For Algebra 2 CP/Honors Summer Review Pcket For Alger CP/Honors Nme Current Course Mth Techer Introduction Alger uilds on topics studied from oth Alger nd Geometr. Certin topics re sufficientl involved tht the cll for some review

More information

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona Implementing utomt Sc 5 ompilers nd Systems Softwre : Lexicl nlysis II Deprtment of omputer Science University of rizon collerg@gmil.com opyright c 009 hristin ollerg NFs nd DFs cn e hrd-coded using this

More information

Presentation Martin Randers

Presentation Martin Randers Presenttion Mrtin Rnders Outline Introduction Algorithms Implementtion nd experiments Memory consumption Summry Introduction Introduction Evolution of species cn e modelled in trees Trees consist of nodes

More information

Here is an example where angles with a common arm and vertex overlap. Name all the obtuse angles adjacent to

Here is an example where angles with a common arm and vertex overlap. Name all the obtuse angles adjacent to djcent tht do not overlp shre n rm from the sme vertex point re clled djcent ngles. me the djcent cute ngles in this digrm rm is shred y + + me vertex point for + + + is djcent to + djcent simply mens

More information

CSCE 531, Spring 2017, Midterm Exam Answer Key

CSCE 531, Spring 2017, Midterm Exam Answer Key CCE 531, pring 2017, Midterm Exm Answer Key 1. (15 points) Using the method descried in the ook or in clss, convert the following regulr expression into n equivlent (nondeterministic) finite utomton: (

More information

Fig.1. Let a source of monochromatic light be incident on a slit of finite width a, as shown in Fig. 1.

Fig.1. Let a source of monochromatic light be incident on a slit of finite width a, as shown in Fig. 1. Answer on Question #5692, Physics, Optics Stte slient fetures of single slit Frunhofer diffrction pttern. The slit is verticl nd illuminted by point source. Also, obtin n expression for intensity distribution

More information

P(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have

P(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have Rndom Numers nd Monte Crlo Methods Rndom Numer Methods The integrtion methods discussed so fr ll re sed upon mking polynomil pproximtions to the integrnd. Another clss of numericl methods relies upon using

More information

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona CSc 453 Compilers nd Systems Softwre 4 : Lexicl Anlysis II Deprtment of Computer Science University of Arizon collerg@gmil.com Copyright c 2009 Christin Collerg Implementing Automt NFAs nd DFAs cn e hrd-coded

More information

CSCI 446: Artificial Intelligence

CSCI 446: Artificial Intelligence CSCI 446: Artificil Intelligence Serch Instructor: Michele Vn Dyne [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.]

More information

2014 Haskell January Test Regular Expressions and Finite Automata

2014 Haskell January Test Regular Expressions and Finite Automata 0 Hskell Jnury Test Regulr Expressions nd Finite Automt This test comprises four prts nd the mximum mrk is 5. Prts I, II nd III re worth 3 of the 5 mrks vilble. The 0 Hskell Progrmming Prize will be wrded

More information

The Greedy Method. The Greedy Method

The Greedy Method. The Greedy Method Lists nd Itertors /8/26 Presenttion for use with the textook, Algorithm Design nd Applictions, y M. T. Goodrich nd R. Tmssi, Wiley, 25 The Greedy Method The Greedy Method The greedy method is generl lgorithm

More information

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS COMPUTATION & LOGIC Sturdy st April 7 : to : INSTRUCTIONS TO CANDIDATES This is tke-home exercise. It will not

More information

An Efficient Divide and Conquer Algorithm for Exact Hazard Free Logic Minimization

An Efficient Divide and Conquer Algorithm for Exact Hazard Free Logic Minimization An Efficient Divide nd Conquer Algorithm for Exct Hzrd Free Logic Minimiztion J.W.J.M. Rutten, M.R.C.M. Berkelr, C.A.J. vn Eijk, M.A.J. Kolsteren Eindhoven University of Technology Informtion nd Communiction

More information

Naming 3D objects. 1 Name the 3D objects labelled in these models. Use the word bank to help you.

Naming 3D objects. 1 Name the 3D objects labelled in these models. Use the word bank to help you. Nming 3D ojects 1 Nme the 3D ojects lelled in these models. Use the word nk to help you. Word nk cue prism sphere cone cylinder pyrmid D A C F A B C D cone cylinder cue cylinder E B E prism F cue G G pyrmid

More information

Lecture 8: Graph-theoretic problems (again)

Lecture 8: Graph-theoretic problems (again) COMP36111: Advned Algorithms I Leture 8: Grph-theoreti prolems (gin) In Prtt-Hrtmnn Room KB2.38: emil: iprtt@s.mn..uk 2017 18 Reding for this leture: Sipser: Chpter 7. A grph is pir G = (V, E), where V

More information

If f(x, y) is a surface that lies above r(t), we can think about the area between the surface and the curve.

If f(x, y) is a surface that lies above r(t), we can think about the area between the surface and the curve. Line Integrls The ide of line integrl is very similr to tht of single integrls. If the function f(x) is bove the x-xis on the intervl [, b], then the integrl of f(x) over [, b] is the re under f over the

More information