graph-algorithms
npx machina-cli add skill parcadei/Continuous-Claude-v3/graph-algorithms --openclawGraph Algorithms
When to Use
Use this skill when working on graph-algorithms problems in graph number theory.
Decision Tree
-
Traversal selection
- BFS: shortest paths (unweighted), level structure
- DFS: cycle detection, topological sort, SCC
-
Shortest path algorithms
Algorithm Use Case Complexity Dijkstra Non-negative weights O((V+E) log V) Bellman-Ford Negative weights O(VE) Floyd-Warshall All pairs O(V^3) -
Minimum Spanning Tree
- Prim's: dense graphs, greedy from vertex
- Kruskal's: sparse graphs, union-find
z3_solve.py prove "cut_property"
-
Network Flow
- Max-flow = min-cut (Ford-Fulkerson)
- Matching via flow network
sympy_compute.py linsolve "flow_conservation"
-
Graph properties
- Spectral: eigenvalues of adjacency matrix
- Connectivity: via DFS/BFS
- Coloring: greedy or SAT reduction
Tool Commands
Sympy_Adjacency
uv run python -m runtime.harness scripts/sympy_compute.py eigenvalues "adjacency_matrix"
Z3_Dijkstra
uv run python -m runtime.harness scripts/z3_solve.py prove "d[v] >= d[u] + w(u,v) for all edges"
Z3_Mst_Cut
uv run python -m runtime.harness scripts/z3_solve.py prove "min_edge_crossing_cut_in_mst"
Sympy_Flow
uv run python -m runtime.harness scripts/sympy_compute.py linsolve "flow_conservation_equations"
Key Techniques
From indexed textbooks:
- [Graph Theory (Graduate Texts in Mathematics (173))] Given two numerical graph invariants i1 and i2, write i1 i2 if we can force i2 to be arbitrarily high on some subgraph of G by assuming that i1(G) is large enough. Formally: write i1 i2 if there exists a function f : N → N such that, given any k ∈ N, every graph G with i1(G) f (k) has a subgraph H with i2(H) k. If i1 i2 as well as i1 i2, write i1 ∼ i2.
- [Graph Theory (Graduate Texts in Mathematics (173))] Find the smallest integer b = b(k) such that every graph of order n with more than kn + b edges has a (k + 1)-edge- connected subgraph, for every k ∈ N. Show that every tree T has at least Δ(T ) leaves. Show that a tree without a vertex of degree 2 has more leaves than other vertices.
- [Graph Theory (Graduate Texts in Mathematics (173))] For every n > 1, nd a bipartite graph on 2n vertices, ordered in such a way that the greedy algorithm uses n rather than 2 colours. Exercises Consider the following approach to vertex colouring. First, nd a max- imal independent set of vertices and colour these with colour 1; then nd a maximal independent set of vertices in the remaining graph and colour those 2, and so on.
- [Graph Theory (Graduate Texts in Mathematics (173))] Show that, for every r ∈ N, every innite graph of upper density s subgraph for every s ∈ N. Deduce that the upper density of innite graphs can only take r−1 has a K r the countably many values of 0, 1, 1 2 , 2 3 , 3 4 Extremal Graph Theory Given a tree T , nd an upper bound for ex(n, T ) that is linear in n and independent of the structure of T , i. Prove the Erd˝os-S´os conjecture for the case when the tree considered is a star.
- [Graph Theory (Graduate Texts in Mathematics (173))] Colouring Slightly more generally, a class G of graphs is called χ-bounded if there exists a function f : N → N such that χ(G) f (r) for every graph G ⊇ Kr in G. In such graphs, then, we can force a Kr subgraph by making χ larger than f (r). Show that the four colour theorem does indeed solve the map colouring problem stated in the rst sentence of the chapter.
Cognitive Tools Reference
See .claude/skills/math-mode/SKILL.md for full tool documentation.
Source
git clone https://github.com/parcadei/Continuous-Claude-v3/blob/main/.claude/skills/math/graph-number-theory/graph-algorithms/SKILL.mdView on GitHub Overview
This skill provides practical strategies for tackling graph-based problems in graph number theory. It covers traversal choices, shortest-path and MST methods, network flow, and key graph properties, with concrete tool commands to apply in practice.
How This Skill Works
You start by identifying the problem class (traversal, shortest paths, MST, or flow) and then apply the most suitable algorithm. The guide maps specific algorithms to problem types (Dijkstra/Bellman-Ford/Floyd-Warshall, Prim/Kruskal, Ford-Fulkerson) and shows how to validate properties using command-line tools like z3_solve.py and sympy_compute.py.
When to Use It
- Finding shortest routes in a weighted graph with non-negative edges.
- Detecting cycles, performing a topological sort, or identifying strongly connected components.
- Choosing between Prim and Kruskal for a minimum spanning tree on graphs with differing density.
- Modeling and solving network flow problems or deriving a maximum matching via flow networks.
- Analyzing spectral properties, connectivity, or performing greedy coloring on graphs.
Quick Start
- Step 1: Identify whether your problem needs traversal, shortest paths, MST, or flow, and note graph weights and density.
- Step 2: Apply the appropriate tool command (e.g., Sympy_Adjacency for eigenvalues; Z3_Dijkstra for d[v] > d[u] + w; Z3_Mst_Cut for min-cut in MST; Sympy_Flow for flow_linsolve).
- Step 3: Interpret results (paths, MST edges, maximum flow, or spectral properties) and verify constraints with the harness tools.
Best Practices
- Start with the problem type and pick the corresponding tool: traversal, shortest path, MST, or flow.
- Match algorithm choice to graph characteristics: Dijkstra for non-negative weights; Bellman-Ford for negatives; Floyd-Warshall for all-pairs on small/dense graphs.
- For MST, prefer Prim on dense graphs and Kruskal on sparse graphs; verify cut properties with z3_solve.py.
- Use Ford-Fulkerson style max-flow formulations when a flow perspective clarifies the problem; consider flow-based matching.
- Explore graph properties with spectral analysis (adjacency eigenvalues) and use greedy or SAT-based coloring when appropriate.
Example Use Cases
- Routing optimization in a logistics network to minimize total travel time.
- Cycle detection and SCC analysis to understand dependencies in a graph.
- Constructing a cost-efficient network using MST in a telecom or data-center graph.
- Maximizing bipartite matchings via a flow network in assignment problems.
- Analyzing connectivity and coloring challenges in large-scale graphs using spectral or greedy methods.