Éducation aux algorithmes et structures de données

VérifiéSûr

Compétences pour créer des implémentations claires, bien documentées et testées d'algorithmes éducatifs en Java.

Spar Skills Guide Bot
DeveloppementIntermédiaire
22/07/2026
Claude CodeCursorCopilot
#algorithms#data-structures#java#documentation#testing

Recommandé pour

Synthèse automatique

Définit les conventions de documentation, de tests et de clarté de code à appliquer dans un dépôt pédagogique d'algorithmes et de structures de données en Java.

Points forts

  • Impose un modèle de commentaire précis pour chaque méthode publique : objectif, approche, paramètres, valeur de retour et complexité en temps/espace
  • Prévoit un en-tête de fichier décrivant l'algorithme, ses cas d'usage, la commande d'exécution et un lien de référence
  • Donne une liste concrète de catégories de tests à couvrir : cas nominal, cas limites, valeurs extrêmes, entrées piégeuses et vérification de performance
  • Couvre un large spectre d'algorithmes (graphes, tris, arbres, DP, union-find) avec des exemples de code commentés ligne à ligne sur le « pourquoi »

Limites

  • Fortement centré sur Java et sur une arborescence de type Bazel/Maven pour les commandes d'exécution citées
  • Ce ne sont que des conventions écrites : aucun linter, script ou seuil de couverture n'est fourni pour les faire respecter
  • La section sur les tests est interrompue et ne détaille ni les frameworks ni les critères de couverture
Quand l'utiliser

À utiliser dès que l'on écrit, refactorise, documente ou teste du code d'algorithmes et de structures de données dans ce dépôt pédagogique.

Quand l'éviter

À éviter sur du code de production où priment la performance, la stabilité des API et des stacks non Java plutôt que la clarté pédagogique.

Analyse de sécurité

Sûr
Score qualité88/100

This skill contains only educational coding conventions and documentation guidance for Java algorithm implementations. It does not instruct any destructive, exfiltrating, obfuscated, or network-based actions, and declares no tools. The content is purely instructional for code quality and testing.

Aucun point d'attention détecté

Comment cette analyse est faite

Exemples

Document an algorithm file
Document every public method in src/main/java/com/williamfiset/algorithms/graphtheory/BellmanFordAdjacencyList.java following our repo conventions, including time and space complexity, and add the file-level header with the Bazel run command.
Add a test class
Write BellmanFordTest.java mirroring the source file: cover the happy path, an empty graph, a single node, negative cycle detection, and a large random graph as a performance sanity check.
Simplify for learners
Refactor my union-find implementation to be easier for beginners to follow, and add inline comments explaining why path compression and union-by-rank are used.

name: algorithms-education description: > Skills and conventions for an educational algorithms and data structures repository. Use this skill whenever working on algorithm implementations, data structure code, LeetCode-style problems, graph theory, dynamic programming, or any Java-based educational coding project. Trigger on mentions of: algorithms, data structures, graph theory, sorting, searching, trees, DP, BFS, DFS, linked lists, heaps, segment trees, union-find, or any request to write, refactor, document, or test educational code. Also trigger when the user asks to "clean up", "simplify", "document", "refactor" or "add tests" to algorithm code.

Algorithms Education Skills

This skill defines the conventions and standards for an educational algorithms repository. The goal is to make every algorithm implementation clear, well-tested, and accessible to learners who may not have deep CS backgrounds.


Skill 1: Code Documentation

Goal: Every file should teach, not just implement.

Method-Level Documentation

Every public method gets a doc comment that explains:

  1. What the method does (in plain English, one sentence)
  2. How it works (brief description of the approach/algorithm)
  3. Parameters — what each input represents
  4. Returns — what the output means
  5. Time/Space complexity — always include Big-O
/**
 * Finds the shortest path from a source node to all other nodes
 * using Bellman-Ford's algorithm. Unlike Dijkstra's, this handles
 * negative edge weights and detects negative cycles.
 *
 * @param graph - adjacency list where graph[i] lists edges from node i
 * @param start - the source node index
 * @param n     - total number of nodes in the graph
 * @return dist array where dist[i] = shortest distance from start to i,
 *         or Double.NEGATIVE_INFINITY if node i is in a negative cycle
 *
 * Time:  O(V * E) — relaxes all edges V-1 times
 * Space: O(V)     — stores distance array
 */

Inline Comments on Key Lines

Comment the why, not the what. Focus on lines where the logic isn't obvious:

// Relax all edges V-1 times. After V-1 passes, shortest paths
// are guaranteed if no negative cycles exist.
for (int i = 0; i < n - 1; i++) {
  for (Edge e : edges) {
    if (dist[e.from] + e.cost < dist[e.to]) {
      dist[e.to] = dist[e.from] + e.cost;
    }
  }
}

// If we can still relax an edge after V-1 passes, that node
// is reachable from a negative cycle — mark it as -infinity.
for (int i = 0; i < n - 1; i++) {
  for (Edge e : edges) {
    if (dist[e.from] + e.cost < dist[e.to]) {
      dist[e.to] = Double.NEGATIVE_INFINITY;
    }
  }
}

File-Level Header

Every file starts with a comment block explaining the algorithm in the file

/**
 * Bellman-Ford Shortest Path Algorithm
 *
 * Computes single-source shortest paths in a weighted graph.
 * Handles negative edge weights and detects negative cycles.
 *
 * Use cases:
 *   - Graphs with negative weights (where Dijkstra fails)
 *   - Detecting negative cycles (e.g., currency arbitrage)
 *
 * Run with:
 *   bazel run //src/main/java/com/williamfiset/algorithms/graphtheory:BellmanFordAdjacencyList
 *
 * @see <a href="https://en.wikipedia.org/wiki/Bellman-Ford_algorithm">Wikipedia</a>
 */

Skill 2: Test Coverage

Goal: Every algorithm has tests that prove it works and teach edge cases.

Test File Structure

Place tests alongside source files or in a tests/ directory. Name test files to mirror the source: BellmanFord.java → BellmanFordTest.java.

What to Test

For every algorithm, cover these categories:

  1. Basic/Happy path — typical input, expected output
  2. Edge cases — empty input, single element, duplicates
  3. Boundary conditions — max/min values, zero, Integer.MAX_VALUE
  4. Known tricky inputs — cases that commonly break naive implementations
  5. Performance sanity check — large input doesn't hang or crash (optional)

Test Naming Convention

Use descriptive names that read like a sentence:

@Test
public void testShortestPathSimpleGraph() { ... }

@Test
public void testDetectsNegativeCycle() { ... }

@Test
public void testSingleNodeGraph() { ... }

@Test
public void testDisconnectedNodes() { ... }

Test Documentation

Each test method gets a brief comment explaining what scenario it covers and why that scenario matters:

/**
 * Graph with a negative cycle reachable from the source.
 * Bellman-Ford should mark affected nodes as NEGATIVE_INFINITY.
 *
 *   0 --5--> 1 --(-10)--> 2 --3--> 1
 *                (creates cycle 1→2→1 with net cost -7)
 */
@Test
public void testDetectsNegativeCycle() {
  // ... test body
}

When Modifying Code, Update Tests

Every code change must be accompanied by:

  • Running existing tests to check for regressions
  • Adding new tests if new behavior is introduced
  • Updating existing tests if method signatures or behavior changed
  • Removing tests only if the feature they cover was deliberately removed

Skill 3: Refactoring and Code Debt

Goal: Keep the codebase clean without losing educational value.

When to Remove Code

Remove code that is:

  • Exact duplicates of another implementation with no added educational value
  • Dead code (unreachable, unused helper methods)
  • Commented-out blocks with no explanation of why they exist
  • Temporary debug/print statements

When to Keep "Duplicate" Code

Keep alternative implementations when they teach different approaches:

// ✓ KEEP — BFS and DFS solutions to the same problem teach different techniques
public int[] bfsSolve(int[][] grid) { ... }
public int[] dfsSolve(int[][] grid) { ... }

// ✓ KEEP — iterative vs recursive shows tradeoffs
public int fibRecursive(int n) { ... }
public int fibIterative(int n) { ... }

// ✗ REMOVE — identical logic, just different variable names
public int search_v1(int[] arr, int target) { ... }
public int search_v2(int[] arr, int target) { ... }

When keeping alternatives, clearly label them with a comment explaining the educational purpose:

/**
 * Recursive implementation of binary search.
 * Compare with binarySearchIterative() to see the iterative approach.
 * The iterative version avoids stack overhead for large arrays.
 */

Debt Checklist

When refactoring, scan for:

  • [ ] Unused imports
  • [ ] Unused variables or parameters
  • [ ] Methods that can be combined or simplified
  • [ ] Magic numbers that should be named constants
  • [ ] Inconsistent naming within the same file
  • [ ] Copy-pasted blocks that should be extracted into a helper

Skill 4: Code Formatting and Consistency

Goal: Uniform style across the entire repository.

Naming Conventions

Use short, clear variable names. Prefer readability through simplicity:

// ✓ GOOD — short and clear
int n = graph.length;
int[] dist = new int[n];
boolean[] vis = new boolean[n];
List<int[]> adj = new ArrayList<>();
Queue<Integer> q = new LinkedList<>();
int src = 0;
int dst = n - 1;

// ✗ BAD — verbose names that clutter algorithm logic
int numberOfNodesInGraph = graph.length;
int[] shortestDistanceFromSource = new int[numberOfNodesInGraph];
boolean[] hasNodeBeenVisited = new boolean[numberOfNodesInGraph];
List<int[]> adjacencyListRepresentation = new ArrayList<>();
Queue<Integer> breadthFirstSearchQueue = new LinkedList<>();
int sourceNodeIndex = 0;
int destinationNodeIndex = numberOfNodesInGraph - 1;

Common short names (use consistently across the repo):

| Name | Meaning | |--------|-------------------------------| | n | number of elements/nodes | | m | number of edges | | i, j | loop indices | | from, to | graph node endpoints | | cost | edge weight | | dist | distance array | | vis | visited array | | adj | adjacency list | | q | queue | | pq | priority queue | | st | stack | | dp | dynamic programming table | | ans | result/answer | | lo | low pointer/bound | | hi | high pointer/bound | | mid | midpoint | | src | source node | | dst | destination node | | cnt | counter | | sz | size | | cur | current element | | prev | previous element | | next | next element (use nxt if shadowing keyword) |

Formatting Rules

  • Braces: opening brace on the same line (if (...) {)
  • Indentation: 2 spaces (no tabs)
  • Blank lines: one blank line between methods, none inside short methods
  • Max line length: 100 characters (soft limit)
  • Imports: group by package, alphabetize within groups, no wildcard imports

Big-O Notation Convention

Always use explicit multiplication and parentheses in Big-O expressions for clarity:

// ✓ GOOD — explicit and unambiguous
// Time:  O(n*log(n))
// Time:  O(n*log^2(n))
// Time:  O(n^2*log(n))

// ✗ BAD — missing multiplication and parentheses
// Time:  O(n log n)
// Time:  O(n log^2 n)
// Time:  O(n^2 log n)

// Simple expressions without multiplication are fine as-is
// Time:  O(n)
// Time:  O(n^2)
// Time:  O(log(n))
// Space: O(n)

For Loop Body on Its Own Line

Always place the body of a for loop on its own line, even for single statements. This improves readability, especially in nested loops:

// ✗ BAD — body on same line as for
for (int j = 0; j < n; j++) augmented[i][j] = matrix[i][j];

// ✓ GOOD — body on its own line
for (int j = 0; j < n; j++)
  augmented[i][j] = matrix[i][j];

// ✓ GOOD — nested for loops, each level on its own line
for (int i = 0; i < n; i++)
  for (int j = 0; j < n; j++)
    for (int k = 0; k < n; k++)
      result[i][j] += m1[i][k] * m2[k][j];

Avoid Java Streams

Streams hurt readability for learners. Use plain loops instead:

// ✗ AVOID — streams obscure the logic for beginners
int sum = Arrays.stream(arr).filter(x -> x > 0).reduce(0, Integer::sum);

// ✓ PREFER — a loop is immediately readable
int sum = 0;
for (int x : arr) {
  if (x > 0) sum += x;
}

Skill 5: Simplification

Goal: The simplest correct code teaches the best.

Simplification Strategies

  1. Reduce nesting — invert conditions, return early
// ✗ AVOID — deep nesting
if (node != null) {
  if (node.left != null) {
    if (node.left.val == target) {
      return true;
    }
  }
}
return false;

// ✓ PREFER — early returns keep code flat
if (node == null) return false;
if (node.left == null) return false;
return node.left.val == target;
  1. Extract repeated logic — but only if it genuinely reduces complexity

  2. Use standard library where it clarifies — Arrays.sort(), Collections.swap(), Math.min(), etc. are fine because learners need to know these exist

  3. Remove unnecessary wrappers — don't wrap a single method call in another method

  4. Prefer arrays over complex data structures when the problem allows it — int[] is clearer than ArrayList<Integer> when the size is known

What NOT to Simplify

  • Don't merge two clearly distinct algorithm phases into one loop just to save lines
  • Don't replace clear if/else chains with ternary operators if it reduces readability
  • Don't remove intermediate variables that give a name to a complex expression

Skill 6: Bug Detection

Goal: Catch bugs proactively whenever touching code.

Bug Scan Checklist

When modifying any lines of code, actively check for and report:

  • [ ] Off-by-one errors — loop bounds, array indices, fence-post problems
  • [ ] Integer overflow — multiplication or addition that could exceed int range
  • [ ] Null/empty checks — missing guards for null arrays, empty collections
  • [ ] Uninitialized values — using variables before assignment (especially in dp arrays)
  • [ ] Wrong comparison — == vs <=, < vs <= in loop conditions
  • [ ] Infinite loops — conditions that never become false, missing increments
  • [ ] Array out of bounds — indexing with i+1, i-1 without range checks
  • [ ] Graph issues — missing visited check (infinite loop in cycles), wrong direction in directed graph
  • [ ] Incorrect base cases — dp[0], recursion base case, empty graph
  • [ ] Mutation bugs — modifying input that caller expects unchanged
  • [ ] Copy vs reference — shallow copy when deep copy needed
  • [ ] Return value misuse — ignoring return value, returning wrong variable

How to Report Bugs

When a bug is found, report it clearly:

🐛 BUG FOUND in BellmanFord.java line 42:
   Loop runs `i < n` but should be `i < n - 1`.
   The extra iteration incorrectly marks reachable nodes as
   being in a negative cycle.
   FIX: Change `i < n` to `i < n - 1`

Skill 7: Algorithm Explanation Comments

Goal: Help learners understand the why behind each algorithm.


Skill 8: Place main method at the bottom

Goal: The main java method should be near the bottom of the Java file for consistency throughout the project

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/algorithms-and-data-structures-education-mrwakd53' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/algorithms-and-data-structures-education-mrwakd53/download' --output '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md.part' && mv '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md.part' '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.

Claude Code
test -f '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md' && test -s '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/algorithms-education' && cp -R '.skill-downloads/algorithms-and-data-structures-education-mrwakd53' '.claude/skills/algorithms-education'

Cursor
test -f '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md' && test -s '.skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/algorithms-education' && cp -R '.skill-downloads/algorithms-and-data-structures-education-mrwakd53' '.cursor/skills/algorithms-education'

OpenSkills

OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.

Installation officielle d’OpenSkills
openskills install './.skill-downloads/algorithms-and-data-structures-education-mrwakd53'

openskills read 'algorithms-and-data-structures-education-mrwakd53'

La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.

Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.

openskills sync

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/algorithms-and-data-structures-education-mrwakd53/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires