Course Test · University: upper level
Graph theory: RatMath answers
The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.
Agrees 20
Libraries used here: core, discrete. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.
- 1.Handshake lemmaAgreesA graph has degree sequence . How many edges does it have? Build one and check.Independent answer, so 6 edges. For example a 5-cycle plus one chord.RatMath code
const g = discrete.graph([[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3]]); [g.size, g.degreeSequence()]Output[6, [3, 3, 2, 2, 2]]
- 2.Bridges and cut verticesAgreesTwo triangles and are joined by the edge . Find the bridges and cut vertices.Independent answerOnly lies on no cycle: it is the one bridge. Removing 3 or 4 disconnects the graph: the cut vertices are 3 and 4.RatMath code
const g = discrete.graph([[1, 2], [2, 3], [3, 1], [3, 4], [4, 5], [5, 6], [6, 4]]); [discrete.bridges(g).map((e) => [e.from, e.to]), discrete.cutVertices(g)]Output[[[3, 4]], [3, 4]]
- 3.Prüfer codesAgreesFind the Prüfer code of the tree with edges .Independent answerRemove the smallest leaf each time and record its neighbour: 1 (4), 2 (4), 3 (4), then 4 is a leaf (5). Code .RatMath code
discrete.prufer(discrete.graph([[1, 4], [2, 4], [3, 4], [4, 5], [5, 6]]))Output[4, 4, 4, 5]
- 4.Counting spanning treesAgreesHow many spanning trees do and have?Independent answerCayley: . A cycle loses any one of its 5 edges: 5.RatMath code
[discrete.spanningTreeCount(discrete.complete(4)), discrete.spanningTreeCount(discrete.cycleGraph(5))]Output[16n, 5n]
- 5.Euler toursAgreesDoes have a closed Euler tour? Does ?Independent answeris connected and every degree is 4 (even): yes, a tour of all 10 edges (11 vertices listed). In every degree is 3 (odd): no.RatMath code
const a = discrete.eulerTour(discrete.complete(5), { closed: true }); const b = discrete.eulerTour(discrete.complete(4), { closed: true }); [a.exists, a.vertices.length, b.exists]Output[true, 11, false]
- 6.Hamilton cyclesAgreesIs the cube graph Hamiltonian? Give a cycle.Independent answerYes: the Gray code and back.RatMath code
const h = discrete.hamiltonCycle(discrete.hypercube(3)); [h.exists, h.cycle.length]Output[true, 9]
- 7.The Petersen graphAgreesFor the Petersen graph give the order, size, girth, diameter, chromatic number, independence number, and whether it is Hamiltonian.Independent answer10 vertices, 15 edges, girth 5, diameter 2, , , and it has no Hamilton cycle.RatMath code
const P = discrete.petersen(); [P.order, P.size, discrete.girth(P).girth, discrete.diameter(P), discrete.chromaticNumber(P).number, discrete.maximumIndependentSet(P).length, discrete.hamiltonCycle(P).exists]Output[10, 15, 5, 2, 3, 4, false]
- 8.PlanarityAgreesWhich of , , are planar?Independent answeris planar. has edges, and (triangle-free) has : neither is planar.RatMath code
const D = discrete; [D.isPlanar(D.complete(4)), D.isPlanar(D.complete(5)), D.isPlanar(D.completeBipartite(3, 3))]Output[true, false, false]
- 9.Kuratowski's theoremAgreesShow the Petersen graph is not planar by finding a Kuratowski subgraph.Independent answerIt contains a subdivision of (it also has as a minor, but no subdivided , since its degrees are 3).RatMath code
const r = discrete.planarity(discrete.petersen()); [r.planar, r.kuratowski.kind]Output[false, "K3,3"]
- 10.Euler's formulaAgreesThe cube graph is planar with 8 vertices and 12 edges. How many faces does a plane drawing have?Independent answer: .RatMath code
const g = discrete.platonic("cube"); const p = discrete.planarity(g); [p.planar, p.faces[0].length, g.order - g.size + p.faces[0].length]Output[true, 6, 2]
planarity returns a plane embedding with its faces (one list per block); the cube has 6, and V − E + F = 2 checks Euler's formula. - 11.Chromatic numberAgreesFind the chromatic number of the wheel with 5 spokes (a hub joined to every vertex of ).Independent answerThe odd rim needs 3 colours and the hub, adjacent to all of them, needs a fourth: .RatMath code
discrete.chromaticNumber(discrete.wheel(5)).numberOutput4
- 12.Chromatic polynomialAgreesFind the chromatic polynomial of .Independent answer: .RatMath code
String(discrete.chromaticPolynomial(discrete.cycleGraph(4)))Outputk^4 − 4k^3 + 6k^2 − 3k
- 13.MatchingsAgreesWhat is the size of a maximum matching in ? Is it perfect?Independent answerHall's condition holds (every set of left vertices has 3 neighbours), so there is a perfect matching of size 3.RatMath code
const m = discrete.maximumMatching(discrete.completeBipartite(3, 3)); [m.size, m.perfect]Output[3, true]
- 14.Max flow, min cutAgreesIn the network (3), (2), (1), (2), (3), find the maximum flow from to .Independent answerThe cut has capacity . Flow: 2, 1, 2: total 5. Max flow min cut .RatMath code
const g = discrete.digraph([["s", "a", 3], ["s", "b", 2], ["a", "b", 1], ["a", "t", 2], ["b", "t", 3]]); discrete.maxFlow(g, "s", "t").valueOutput5
- 15.IsomorphismAgreesand two disjoint triangles are both 2-regular on 6 vertices. Are they isomorphic?Independent answerNo: is connected and the triangles are not (also, one has girth 6 and the other 3).RatMath code
discrete.isIsomorphic(discrete.cycleGraph(6), discrete.disjointUnion(discrete.cycleGraph(3), discrete.cycleGraph(3)))Outputfalse
- 16.Counting walksAgreesHow many closed walks of length 3 start and end at a given vertex of ? How many walks of length 3 join two different vertices?Independent answerWith and : . So (the ordered triangles through ) and .RatMath code
const W = discrete.walks(discrete.complete(4), 3).matrix; [W[0][0], W[0][1]]Output[6n, 7n]
- 17.SpectrumAgreesFind the eigenvalues of the adjacency matrix of .Independent answer; has eigenvalues 4, 0, 0, 0, so has 3 and (three times).RatMath code
discrete.spectrum(discrete.complete(4)).eigenvalues.map((e) => [e.text, e.multiplicity])Output[["−1", 3], ["3", 1]]
- 18.Turán's theoremAgreesWhat is the largest number of edges in a triangle-free graph on 6 vertices?Independent answerMantel/Turán: , attained by .RatMath code
discrete.turan(6, 2).sizeOutput9
- 19.Cliques and independenceAgreesFind the clique number of the Petersen graph and of its complement.Independent answerPetersen has girth 5, so it has no triangle: . A clique in the complement is an independent set in , so .RatMath code
const P = discrete.petersen(); [discrete.maximumClique(P).length, discrete.maximumClique(P.complement()).length]Output[2, 4]
- 20.Bipartite graphsAgreesIs the cube graph bipartite? Is the Petersen graph?Independent answer: yes, split by the parity of the number of 1s. Petersen: no, it has 5-cycles.RatMath code
[discrete.isBipartite(discrete.hypercube(3)), discrete.isBipartite(discrete.petersen())]Output[true, false]