shortest-paths

Select and apply shortest-path algorithms for weighted graphs with negative edges.

7|Updated Apr 24, 2026
One-click install
npx skills add https://github.com/Arcadi4/nerdy --skill shortest-paths
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: shortest-paths
Source: https://github.com/Arcadi4/nerdy/tree/main/clrs/shortest-paths
Command: npx skills add https://github.com/Arcadi4/nerdy --skill shortest-paths

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Identify and select the correct shortest-path algorithm for a given graph (directed/undirected, weighted/unweighted, with possible negative edges or cycles), and produce the required outputs (distances, predecessor trees, actual paths, or cycle witnesses) under a clear production contract.

Core Features & Use Cases

  • Determine problem shape, weight semantics, and graph representation, choose the appropriate algorithm (unweighted BFS, DAG relaxation, Bellman-Ford, Dijkstra, Floyd-Warshall, Johnson, or transitive closure) and specify outputs.
  • Provide production-ready output contracts for distances, paths, predecessor structures, and cycle witnesses, with explicit handling of negative cycles and unreachable nodes.
  • Apply the CLRS-inspired relaxation and reweighting framework to justify algorithm choices and translate theory into a robust API contract or library interface.

Quick Start

Define the problem graph and constraints, select the matching shortest-path algorithm based on preconditions, and produce the distances, paths, and reconstruction metadata with clear safety contracts.

Frequently Asked Questions about shortest-paths

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose the right shortest-path algorithm for a weighted graph?▼

To detect negative cycles in shortest-path problems, apply the Bellman-Ford algorithm and check for continued distance relaxation after V-1 iterations. This Skill provides cycle witnesses and explicit handling for unreachable nodes.

Can Dijkstra handle graphs with negative edge weights?▼

Dijkstra cannot handle negative edge weights. For graphs with negative edges, use Bellman-Ford or Johnson's algorithm, which supports reweighting to apply Dijkstra safely while maintaining correct shortest-path distances.

How do I reconstruct the actual shortest path and not just the distance?▼

To reconstruct the actual shortest path, the algorithm maintains a predecessor tree during relaxation. This Skill outputs predecessor structures and path reconstruction metadata alongside distance arrays under a clear production contract.

When should I use Floyd-Warshall instead of single-source shortest path algorithms?▼

Use Floyd-Warshall when you need all-pairs shortest paths or transitive closure across directed graphs. Single-source algorithms like Dijkstra or Bellman-Ford are more efficient when you only need distances from one starting node.

Does this approach work for both directed and undirected graph representations?▼

Yes, this approach works for directed and undirected graphs. It applies the CLRS-inspired relaxation framework to solve single-source, all-pairs, or reachability questions while accounting for graph representation and production constraints.