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. 1.Handshake lemmaAgrees
    A graph has degree sequence 3,3,2,2,23, 3, 2, 2, 2. How many edges does it have? Build one and check.
    Independent answer
    ∑deg⁡=12=2∣E∣\sum \deg = 12 = 2|E|, 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. 2.Bridges and cut verticesAgrees
    Two triangles {1,2,3}\{1,2,3\} and {4,5,6}\{4,5,6\} are joined by the edge 3–43\text{–}4. Find the bridges and cut vertices.
    Independent answer
    Only 3–43\text{–}4 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. 3.Prüfer codesAgrees
    Find the Prüfer code of the tree with edges 1–4,2–4,3–4,4–5,5–61\text{–}4, 2\text{–}4, 3\text{–}4, 4\text{–}5, 5\text{–}6.
    Independent answer
    Remove the smallest leaf each time and record its neighbour: 1 (4), 2 (4), 3 (4), then 4 is a leaf (5). Code (4,4,4,5)(4, 4, 4, 5).
    RatMath code
    discrete.prufer(discrete.graph([[1, 4], [2, 4], [3, 4], [4, 5], [5, 6]]))
    Output
    [4, 4, 4, 5]
  4. 4.Counting spanning treesAgrees
    How many spanning trees do K4K_4 and C5C_5 have?
    Independent answer
    Cayley: 44−2=164^{4-2} = 16. 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. 5.Euler toursAgrees
    Does K5K_5 have a closed Euler tour? Does K4K_4?
    Independent answer
    K5K_5 is connected and every degree is 4 (even): yes, a tour of all 10 edges (11 vertices listed). In K4K_4 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. 6.Hamilton cyclesAgrees
    Is the cube graph Q3Q_3 Hamiltonian? Give a cycle.
    Independent answer
    Yes: the Gray code 000,001,011,010,110,111,101,100000, 001, 011, 010, 110, 111, 101, 100 and back.
    RatMath code
    const h = discrete.hamiltonCycle(discrete.hypercube(3));
    [h.exists, h.cycle.length]
    Output
    [true, 9]
  7. 7.The Petersen graphAgrees
    For the Petersen graph give the order, size, girth, diameter, chromatic number, independence number, and whether it is Hamiltonian.
    Independent answer
    10 vertices, 15 edges, girth 5, diameter 2, χ=3\chi = 3, α=4\alpha = 4, 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. 8.PlanarityAgrees
    Which of K4K_4, K5K_5, K3,3K_{3,3} are planar?
    Independent answer
    K4K_4 is planar. K5K_5 has 10>3⋅5−6=910 > 3\cdot5 - 6 = 9 edges, and K3,3K_{3,3} (triangle-free) has 9>2⋅6−4=89 > 2\cdot6 - 4 = 8: 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. 9.Kuratowski's theoremAgrees
    Show the Petersen graph is not planar by finding a Kuratowski subgraph.
    Independent answer
    It contains a subdivision of K3,3K_{3,3} (it also has K5K_5 as a minor, but no subdivided K5K_5, since its degrees are 3).
    RatMath code
    const r = discrete.planarity(discrete.petersen());
    [r.planar, r.kuratowski.kind]
    Output
    [false, "K3,3"]
  10. 10.Euler's formulaAgrees
    The cube graph is planar with 8 vertices and 12 edges. How many faces does a plane drawing have?
    Independent answer
    V−E+F=2V - E + F = 2: F=2−8+12=6F = 2 - 8 + 12 = 6.
    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. 11.Chromatic numberAgrees
    Find the chromatic number of the wheel with 5 spokes (a hub joined to every vertex of C5C_5).
    Independent answer
    The odd rim needs 3 colours and the hub, adjacent to all of them, needs a fourth: χ=4\chi = 4.
    RatMath code
    discrete.chromaticNumber(discrete.wheel(5)).number
    Output
    4
  12. 12.Chromatic polynomialAgrees
    Find the chromatic polynomial of C4C_4.
    Independent answer
    P(Cn,k)=(k−1)n+(−1)n(k−1)P(C_n, k) = (k - 1)^n + (-1)^n(k - 1): (k−1)4+(k−1)=k4−4k3+6k2−3k(k-1)^4 + (k - 1) = k^4 - 4k^3 + 6k^2 - 3k.
    RatMath code
    String(discrete.chromaticPolynomial(discrete.cycleGraph(4)))
    Output
    k^4 − 4k^3 + 6k^2 − 3k
  13. 13.MatchingsAgrees
    What is the size of a maximum matching in K3,3K_{3,3}? Is it perfect?
    Independent answer
    Hall's condition holds (every set of kk 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. 14.Max flow, min cutAgrees
    In the network s→as\to a (3), s→bs\to b (2), a→ba\to b (1), a→ta\to t (2), b→tb\to t (3), find the maximum flow from ss to tt.
    Independent answer
    The cut {s}\{s\} has capacity 3+2=53 + 2 = 5. Flow: s ⁣→ ⁣a ⁣→ ⁣ts\!\to\!a\!\to\!t 2, s ⁣→ ⁣a ⁣→ ⁣b ⁣→ ⁣ts\!\to\!a\!\to\!b\!\to\!t 1, s ⁣→ ⁣b ⁣→ ⁣ts\!\to\!b\!\to\!t 2: total 5. Max flow == min cut =5= 5.
    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").value
    Output
    5
  15. 15.IsomorphismAgrees
    C6C_6 and two disjoint triangles are both 2-regular on 6 vertices. Are they isomorphic?
    Independent answer
    No: C6C_6 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)))
    Output
    false
  16. 16.Counting walksAgrees
    How many closed walks of length 3 start and end at a given vertex of K4K_4? How many walks of length 3 join two different vertices?
    Independent answer
    With A=J−IA = J - I and J2=4JJ^2 = 4J: A3=J3−3J2+3J−I=16J−12J+3J−I=7J−IA^3 = J^3 - 3J^2 + 3J - I = 16J - 12J + 3J - I = 7J - I. So (A3)vv=6(A^3)_{vv} = 6 (the 3⋅23\cdot2 ordered triangles through vv) and (A3)uv=7(A^3)_{uv} = 7.
    RatMath code
    const W = discrete.walks(discrete.complete(4), 3).matrix;
    [W[0][0], W[0][1]]
    Output
    [6n, 7n]
  17. 17.SpectrumAgrees
    Find the eigenvalues of the adjacency matrix of K4K_4.
    Independent answer
    A=J−IA = J - I; JJ has eigenvalues 4, 0, 0, 0, so AA has 3 and −1-1 (three times).
    RatMath code
    discrete.spectrum(discrete.complete(4)).eigenvalues.map((e) => [e.text, e.multiplicity])
    Output
    [["−1", 3], ["3", 1]]
  18. 18.Turán's theoremAgrees
    What is the largest number of edges in a triangle-free graph on 6 vertices?
    Independent answer
    Mantel/Turán: ⌊62/4⌋=9\lfloor 6^2/4\rfloor = 9, attained by K3,3K_{3,3}.
    RatMath code
    discrete.turan(6, 2).size
    Output
    9
  19. 19.Cliques and independenceAgrees
    Find the clique number of the Petersen graph and of its complement.
    Independent answer
    Petersen has girth 5, so it has no triangle: ω=2\omega = 2. A clique in the complement is an independent set in PP, so ω(Pˉ)=α(P)=4\omega(\bar P) = \alpha(P) = 4.
    RatMath code
    const P = discrete.petersen();
    [discrete.maximumClique(P).length, discrete.maximumClique(P.complement()).length]
    Output
    [2, 4]
  20. 20.Bipartite graphsAgrees
    Is the cube graph Q3Q_3 bipartite? Is the Petersen graph?
    Independent answer
    Q3Q_3: 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]