| name | algorithms |
| description | This skill should be used when choosing "data structures", "Map vs ETS vs gb_trees performance", evaluating "hash functions", needing "HyperLogLog or bloom/cuckoo filters", or comparing OTP built-ins against specialized alternatives for Elixir |
Modern Algorithms and Data Structures
Overview
Use OTP built-ins first. Escalate to specialized structures only when profiling shows a bottleneck. For most Elixir applications, Map, MapSet, List, and the OTP modules cover 95% of needs.
Quick Decision
What are you solving?
Data storage/lookup โ See ets-and-persistent-term.md, otp-builtins.md
Concurrent shared state โ See concurrent-data-structures.md, ets-and-persistent-term.md
Graph/dependency problem โ See graph-algorithms.md
Text search/matching โ See string-and-text.md
Location/spatial โ See spatial.md
Time ranges/scheduling โ See interval-and-range.md
Streaming metrics โ See streaming-algorithms.md
Large-scale counting/sets โ See probabilistic.md
Hashing โ See hash-functions.md
Compression โ See compression.md
Sorting large datasets โ See sorting-and-search.md
Optimization/constraints โ See optimization.md
Statistics/analytics โ See statistics.md
Common Mistakes
- GenServer as concurrent cache: Serializes reads; use ETS with
read_concurrency: true
- Application.get_env in hot paths: Use
:persistent_term for config read on every request
- Lists as queues:
queue ++ [item] is O(n); use :queue for O(1)
- GenServer as counter: Use
:atomics or :counters instead
- MD5/SHA1 for non-crypto: 60ร slower than xxHash3
- Exact counting at scale: HyperLogLog uses 16 KB where MapSet uses 800 MB (100M items)
Reference Files
Read the file that matches your current problem:
ets-and-persistent-term.md โ When: Need concurrent shared state or config cache. ETS table types, concurrency options, cache/rate-limiter patterns, :persistent_term for config
otp-builtins.md โ When: Looking for queue, tree, set, or counter primitives. :queue, :gb_trees, :gb_sets, :atomics, :counters, :array, Okasaki structures
graph-algorithms.md โ When: Working with dependencies, networks, or paths. :digraph/:digraph_utils patterns: topological sort, shortest path, cycle detection, dependency resolution
string-and-text.md โ When: Building search, fuzzy matching, or autocomplete. Fuzzy matching (Levenshtein, Jaro-Winkler), full-text search (tsvector, pg_trgm), autocomplete
concurrent-data-structures.md โ When: Need lock-free or high-concurrency patterns. CAS with :atomics, lock-free patterns, ETS concurrency, :counters write_concurrency
spatial.md โ When: Working with geographic data or proximity queries. PostGIS (ST_DWithin, ST_Contains), geohashing, Haversine distance
interval-and-range.md โ When: Handling time ranges, scheduling, or overlap detection. Postgres range types, overlap detection, exclusion constraints, scheduling
streaming-algorithms.md โ When: Computing metrics over unbounded data streams. Sliding windows, EMA, reservoir sampling, streaming percentiles
optimization.md โ When: Solving constraint, scheduling, or resource allocation problems. Dynamic programming, greedy, constraint satisfaction, gradient descent (Nx), simulated annealing, linear programming, when to push to Postgres
statistics.md โ When: Need analytics, anomaly detection, or A/B testing. Descriptive stats (Postgres and Elixir), anomaly detection (Z-score, IQR), A/B testing, Explorer DataFrames, histograms, correlation
compression.md โ When: Need to compress data for storage or transfer. :zlib, Zstd, LZ4, :erlang.term_to_binary compressed option
Commands
/algorithm-research โ Deep research with academic paper citations
/benchmark โ Create Benchee benchmarks to compare data structure alternatives
Related Skills
- performance-analyzer: Profiling, benchmarking, latency analysis
- distributed-systems: Consensus and replication algorithms
- elixir-patterns: OTP process patterns, ETS usage
Use the algorithms-researcher agent for deep research with paper citations.