← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Graphs

Data Structures Intermediate
debt(d7/e5/b5/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated detection is 'no', and the code_pattern describes recognizing a V×V adjacency matrix for a sparse graph or missing graph representation entirely — neither of which any standard linter or SAST tool flags automatically. Only a careful reviewer or profiler catching memory bloat would catch these misuses.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests switching to adjacency lists, but the common_mistakes include several distinct issues (cycle detection, directed vs undirected semantics, visited sets for BFS/DFS). Correcting all misuses typically requires restructuring the graph representation and adjusting traversal logic across multiple algorithms or components, going beyond a single-line patch.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The term applies to web and CLI contexts broadly, and choosing the wrong representation (adjacency matrix for sparse graphs) or missing cycle detection imposes ongoing costs — every algorithm built on top of a wrong representation must work around it. However, it doesn't dominate the entire codebase architecture, keeping it below b7.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field explicitly states that developers conflate trees and graphs, treating them as separate concepts when trees are a special case of graphs. Additionally, common mistakes like treating directed edges as undirected and forgetting visited sets in cyclic graphs are well-documented but frequently encountered surprises for developers new to graph algorithms.

About DEBT scoring →

Also Known As

directed graph undirected graph DAG adjacency list

TL;DR

A collection of nodes (vertices) connected by edges — directed or undirected, weighted or unweighted. The most general data structure, modelling networks, dependencies, and relationships.

Explanation

A graph G = (V, E) has vertices V and edges E. Directed graphs have one-way edges; undirected have two-way. Weighted graphs assign costs to edges. Representations: adjacency matrix (O(V²) space, O(1) edge lookup), adjacency list (O(V+E) space, better for sparse graphs). Cycles: DAGs (Directed Acyclic Graphs) have no cycles — used for dependency resolution (Composer), build systems, and topological sorting. Trees are DAGs with one path between any two nodes.

Common Misconception

Trees are not graphs — trees are a special case of graphs (connected DAG with no cycles); all trees are graphs but not all graphs are trees.

Why It Matters

Composer's dependency resolution, social network connections, route finding, and task scheduling are all graph problems — knowing the data structure enables choosing the right algorithm.

Common Mistakes

  • Adjacency matrix for sparse graphs — wastes O(V²) memory when most edges don't exist.
  • Not detecting cycles before topological sort — Kahn's algorithm or DFS detects cycles.
  • Treating directed edges as undirected — in a dependency graph, A depends on B is not the same as B depends on A.
  • Infinite loops without a visited set in BFS/DFS on cyclic graphs.

Code Examples

✗ Vulnerable
// Adjacency matrix for sparse social graph — 1M users = 1TB memory:
$matrix = array_fill(0, 1000000, array_fill(0, 1000000, 0));
// 10^12 entries for a graph with ~1 billion edges
✓ Fixed
// Adjacency list — O(V+E) space:
$graph = [
    'A' => ['B', 'C'],
    'B' => ['D'],
    'C' => ['D', 'E'],
    'D' => [],
    'E' => [],
];
// Only stores actual edges — efficient for sparse graphs
// 5 vertices, 5 edges — exactly 10 entries total

Added 16 Mar 2026
Edited 22 Mar 2026
Views 64
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 2 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 2 pings M 1 ping T 0 pings W
No pings yet today
SEMrush 1
Amazonbot 16 Perplexity 11 Ahrefs 6 Scrapy 4 ChatGPT 3 Unknown AI 2 Google 2 Claude 2 Majestic 1 Meta AI 1 Bing 1 PetalBot 1 SEMrush 1
crawler 46 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Medium
⚡ Quick Fix
Represent sparse graphs (social networks, dependency trees) as adjacency lists ($graph[$node][] = $neighbour) — use adjacency matrices only for dense graphs where every node connects to many others
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
V×V adjacency matrix for sparse graph wasting O(V²) memory; no graph representation for dependency resolution or social network features
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: Class Tests: Update


✓ schema.org compliant