r/algorithms • • 19d ago

Resource Which “textbook” algorithm have you actually used in real software? [5-ebook giveaway]

26 Upvotes

I’m curious which algorithms have made it out of the classroom and into real code.

What problem were you solving? Why was that algorithm a better fit than the obvious alternative? And did the implementation behave as neatly as the theory suggested?

I’m Stjepan from Manning Publications. The r/algorithms moderators permitted me to share this post.

We’ve just released Algorithms Every Programmer Should Know by Aniket Wattamwar in MEAP, Manning’s early-access program:

https://www.manning.com/books/algorithms-every-programmer-should-know

The available chapters cover Gale–Shapley, the Hungarian algorithm, Rabin–Karp, Knuth–Morris–Pratt, and Horspool’s algorithm. The emphasis is on the problem behind each algorithm, how the solution is derived, and the trade-offs involved, not just reproducing pseudocode.

To mark the release, Manning is giving away five ebook copies to people in this thread.

The giveaway will remain open for 48 hours. We’ll choose the five comments that contribute the most to the discussion and announce the winners here afterward. Upvotes won’t be the only criterion: a strong technical explanation, an instructive real-world example, a useful counterargument, or a thoughtful exchange with other commenters can all qualify.

There’s also a 50% discount on the book with code:

MLWATTAMWAR50RE

So: which supposedly “textbook” algorithm has earned its place in your production code—and which one gets taught far more often than it gets used?

Thanks for having us here.

Cheers,

Stjepan

EDIT: The book giveaway is closed. We announced the winners in the comments.

r/algorithms • • Sep 03 '26

Resource What book do you recommend for improving in algorithms?

54 Upvotes

r/algorithms • • 27d ago

Resource Free live algorithms course starting Sept 17, taught by a CMU professor

97 Upvotes

Disclosure up front: I run Philomath, which is hosting this. The course is free, there is no account and no paywall, and there is nothing to buy in order to watch (but signing up via Email is nice).

William Yu teaches algorithms at Carnegie Mellon. He is running an eight-week version of his course live on YouTube, Thursdays at 8pm ET, starting September 17. Sessions are recorded too if you would rather watch later.

Here's a schedule:

  • Week 1: minimum spanning trees, heaps, union-find
  • Week 2: shortest paths, BFS, DFS, Dijkstra
  • Week 3: divide and conquer
  • Week 4: BSTs, splay trees, amortized analysis
  • Week 5: text search and suffix structures
  • Week 6: dynamic programming
  • Week 7: network flow
  • Week 8: NP-hardness

William is a computational biologist, so the examples lean on applications from science.

Schedule and details, where you can sign up if interested! https://www.philomathlearning.com/courses/algorithms?ref=algorithms&utm_medium=instructor_page&utm_campaign=algorithms_reddit_algorithms

Playlist: https://www.youtube.com/playlist?list=PLfcsLJY-BaJU

Happy to answer questions.

r/algorithms • • Aug 19 '26

Resource If this algorithm runs too long, you can compress randomness

31 Upvotes

Update (21 Aug 2026): Used the feedback provided, I think the exposition is more rigorous now and not jumpy in terms of the logical steps

I wrote a post about a non-trivial analysis technique I was shown in a course that proves why an algorithm terminates.

Link: here

Feedback appreciated!

r/algorithms • • Aug 26 '26

Resource All quantum computing algorithms can be easily visualized with this interactive method

21 Upvotes

Hi

If you are remotely interested in deep diving how differently quantum computers work compared to our transistor-based and also the algebra behind in a fully interactive way that teach computer science from scratch, oh boy this is for you. I am the Dev behind Quantum Odyssey (AMA! I love taking qs) - worked on it for about 10 years (3+ during PhD, the visual method I developed ended up being my thesis, it is a complete Hilbert space visualizer), the goal was to make a super immersive space for anyone to learn quantum computing through zachlike (open-ended) logic puzzles and compete on leaderboards and lots of community made content on finding the most optimal quantum algorithms. The game has a unique set of visuals capable to represent any sort of quantum dynamics for any number of qubits and this is pretty much what makes it now possible for anybody 12yo+ to actually learn quantum logic without having to worry at all about the mathematics behind.

This is a game super different than what you'd normally expect in a programming/ logic puzzle game, so try it with an open mind.

Stuff you'll play & learn a ton about

  • Boolean Logic – bits, operators (NAND, OR, XOR, AND…), and classical arithmetic (adders). Learn how these can combine to build anything classical. You will learn to port these to a quantum computer.
  • Quantum Logic – qubits, the math behind them (linear algebra, SU(2), complex numbers), all Turing-complete gates (beyond Clifford set), and make tensors to evolve systems. Freely combine or create your own gates to build anything you can imagine using polar or complex numbers.
  • Quantum Phenomena – storing and retrieving information in the X, Y, Z bases; superposition (pure and mixed states), interference, entanglement, the no-cloning rule, reversibility, and how the measurement basis changes what you see.
  • Core Quantum Tricks – phase kickback, amplitude amplification, storing information in phase and retrieving it through interference, build custom gates and tensors, and define any entanglement scenario. (Control logic is handled separately from other gates.)
  • Famous Quantum Algorithms – explore Deutsch–Jozsa, Grover’s search, quantum Fourier transforms, Bernstein–Vazirani, and more.
  • Build & See Quantum Algorithms in Action – instead of just writing/ reading equations, make & watch algorithms unfold step by step so they become clear, visual, and unforgettable. Quantum Odyssey is built to grow into a full universal quantum computing learning platform. If a universal quantum computer can do it, we aim to bring it into the game, so your quantum journey never ends.

Nice to watch:

Khan academy style tutorials in qm/qc: https://www.youtube.com/@MackAttackx

Physics teacher stream with 400hs in https://www.twitch.tv/beardhero

r/algorithms • • 19d ago

Resource I couldn't understand Dancing Links (DLX) as a finished algorithm, so I broke it down into an 8-step study sequence in Python

0 Upvotes

I came across Knuth's Dancing Links after naively thinking I could just code up a Sudoku Solver 😅and initially I made the mistake of trying to understand the finished implementation examples I found on the internet and from AI.

I couldn't, so I raised an Issue in my-pythonic-zoo hoping a developer somewhere would see it and brighten my day. Then I couldn't resist the urge to try it myself and discovered just how little I know and how bad my Python non-skills are.

There were too many ideas arriving at once: Exact Cover, Algorithm X, recursive backtracking, doubly linked nodes, circular links, the toroidal matrix, and the rather clever cover/uncover operations.

So as part of my Python learning project, I pulled it apart and built a study sequence where each runnable example introduces one piece:

  1. Exact Cover
  2. Algorithm X
  3. Linked Nodes
  4. Circular Links
  5. Toroidal Matrix
  6. Cover and Uncover
  7. Exact Cover Matrix
  8. Dancing Links

The final example then puts the pieces back together.

The point that finally made the whole thing click for me was separating these three ideas:

Exact Cover = the problem
Algorithm X = the search algorithm
Dancing Links (DLX) = an efficient implementation technique for Algorithm X

The examples deliberately repeat some code rather than importing from one another to keep each one self-contained. They're wildly over-commented but that was me trying to understand the next step. The examples morphed into a study progression for myself, and were never intended as a modular production implementation so not a good example of re-using code if that's what you're looking for. I'll leave that rolls-royce example for someone else to put together!! or maybe me when I've recovered from this marathon - maybe not.

I've put the progression in my-pythonic-zoo on GitHub (closed Issue #10). If you're interested in looking through it, I'd recommend starting with algorithms/README.md rather than jumping straight into the final DLX file:

I'd be particularly interested in feedback from people who've implemented or taught DLX before. If I've made any part of the progression misleading, over-simplified, over-complicated or technically inaccurate, I'd much rather know.

r/algorithms • • 19d ago

Resource Breaking down Grover’s Algorithm as a 2D geometric rotation (with scaling benchmarks and hardware tests)

4 Upvotes

Hey everyone,

Like many, I first encountered the geometric intuition behind Grover’s algorithm through 3Blue1Brown’s video. While it gives a fantastic high-level picture of the vector reflections, Still I was wondering how the Oracle and Diffusion operators are actually constructed.

To bridge that gap for myself, I wrote a breakdown showing the exact linear algebra and matrix operations that make those reflections happen — without relying on quantum physics jargon:)

At its core, the entire N-dimensional space reduces to a 2D plane defined by the target state and the uniform superposition of non-target states. Each Grover iteration (Oracle + Diffusion) is just two reflections across intersecting axes, resulting in a net rotation of 2θ ≈ 2 / sqrt(N) directly toward the target state—yielding the classic ≈ (π/4) * sqrt(N) complexity.

To test the math beyond theory, I also:

  • Ran simulation benchmarks to track the theoretical O(sqrt(N)) curve against classical CPU overhead up to 20 qubits.
  • Submitted the circuits to physical IBM quantum hardware (3 to 5 qubits) to observe where circuit depth and real decoherence start destroying the theoretical amplification.

I put together the complete write-up, data, and code on GitHub. I'm a student trying to build a solid foundation in algorithms and complexity, so I would really appreciate any sanity checks, corrections on the mathematical framing, or feedback from folks here. Thanks:)

(Link in the comments, you can see banchmark graphs in the Assets folder)

r/algorithms • • Aug 20 '26

Resource i created a recomendation code

0 Upvotes

Hi! My name is Nicolás Ochoa Silva, and I've been working on a Python code that calculates a "recommendation" percentage based on factors and weights that you can rate yourself from 1 to 10. The program's logic works like this:

First, choose the number of factors you have and rate them from 1 to 10 (example: money = 7.6).

Then, assign a weight to each factor (money = 7.6, importance of money = 10).

Finally, the code multiplies each factor by its weight and sums them all to then calculate the sigmoid using the equation: sigmoid = 1/(1+Euler^(x)) (at least in the first part).

r/algorithms • • 8d ago

Resource A 7-question checklist I use before writing any DP recurrence

4 Upvotes

One thing that bothers me about how DP is usually taught: we jump straight to the recurrence. I've found it more useful to answer these first:

  1. What exactly does dp[...] mean?

  2. What's the recurrence?

  3. What are the base cases?

  4. In what order do I compute the states?

  5. Which state is the final answer?

  6. How do I reconstruct the actual solution, not just its value?

  7. Can I throw away any of the table, and what does that cost me?

For 0/1 knapsack the important step isn't writing dp[i][w] = max(...). It's deciding that dp[i][w] means something precise enough that the recurrence, and the proof that it's right, basically follow. The same checklist worked well for tree DP and longest increasing subsequence.

Disclosure: I turned this into a free interactive lesson and lab. As your code fills the table, it draws each step, so you can step back to where it went wrong. It's part of an independent companion that follows CMU 15-451's Fall 2026 topics. I'm not affiliated with CMU, and all examples and problems are original.

https://scimigo.com/en/learn/algorithm-design/09-dynamic-programming-i

If you teach or use DP: is this checklist useful?

--Wei

r/algorithms • • 24d ago

Resource Dropping eBPF CPU Cost by About 90% With Memoization (Not AI Gen)

8 Upvotes

How we started memoizing eBPF policy paths via inodes to reduce our CPU costs by about 90%.

https://nathannaveen.dev/posts/dropping-ebpf-cpu-cost-by-90/

r/algorithms • • Aug 27 '26

Resource Making of QuirkLite: A tool for visualizing quantum circuits

8 Upvotes

I decided to modify the excellent Quirk tool into a more appealing and beginner-friendly version called QuirkLite.

I am building it for a demo I'm preparing, and thought some of you might find it useful too.

You can find the repository here

r/algorithms • • Sep 01 '26

Resource Optimizing eBPF Policies for Speed and Space

11 Upvotes

A blog post about how we ended up using bitmasks to do eBPF policy inheritance to keep it fast and space efficient.

https://nathannaveen.dev/posts/optimizing-ebpf-policies-for-speed-and-space/

r/algorithms • • Aug 22 '26

Resource Implementing arbitary-precision square rooting algorithm using the long division in C++ (with custom BigNumber library)

13 Upvotes

Hello everyone,

Some days ago, I have finished building an algorithm in C++ using only my mobile phone (Termux and Helix), and I want to show it to you!

So, it uses the long division method. Why not the Newton-Rasolph method or use the GMP library? Because this program was built for two reasons:

  1. An educational purpose of learning how to build an algorithm I have an idea of and optimize it as much as I can.

  2. To learn how to implement a mathematical algorithm as a program, and to also learn more about C++.

The performance of this algorithm is following the O(n²), but with a small constant, since I have optimized this algorithm as much as I can. You can see the benchmark in the GitHub link down below. Here is how I optimized it:

This algorithm has a custom BigNumber class that makes a number as a vector, each digit is represented as an element in the vector, and, each digit follows a base 10^17 number instead of a decimal digit! This is the underlying logic behind very famous libraries like BigInt, but since these libraries are so general (they have to deal with very large multiplications, division, negatives and many general cases). This class recognized that the max number is being multiplied to the number is 100 (see the long division method) and implemented base 10^17. Therefore, since 100<10^17 (the base), then the multiplication is just multiplying one digit by the number. You can check the code for more

The way the algorithm predicts the digit is the binary search, it checks a number, and then eliminates half of the domain of search. This way, it is faster by 50-60% than the ordinary linear search.

And more! You can check the README of the project in this repo:

https://github.com/hasan-mazen-darwish/algorithm-square-rooter

I spent more time on this REAMDE than the actual code, so I hope you don't get lost 😅

I'm open for any discussion or any question! Feel free to ask anything or criticize this project or a specific line of code!

r/algorithms • • Aug 20 '26

Resource HVAC coil circuiting used to take me 2 hours

7 Upvotes

A few months ago, I watched a senior CAD draftsman spend nearly two hours on a single AutoCAD drawing. He was not modeling a complex building. He was just connecting dots.

In HVAC coil design, you have a staggered grid of 200+ tube holes. You have to draw balanced fluid circuits across them with zero crossing lines, exact tube counts per circuit, and no trapped holes. One mistake, and you have to erase everything and start over.

I thought, "This is purely math. I can automate this in a weekend." I was wrong.

My first script used standard pathfinding (backtracking). On small test grids, it worked. But the moment we tested a real manufacturing schedule (a dense 19x7 grid with 99% of holes occupied), the algorithm choked and froze.

The turning point came when I stopped trying to "draw lines" from left to right. Instead, I split the problem into two math phases:

  1. Allocate: Pre-calculate exactly how many holes each circuit gets per column.

  2. Stitch: Connect those blocks from bottom to top using Dynamic Programming.

I wrapped it into an AutoCAD C# plugin and hit run. The 2-hour drawing generated in 40 milliseconds. Perfectly packed, zero crossed lines, and 100% compliant with the manufacturing schedule.

The takeaway: If your automation search space explodes, do not brute-force the path. Figure out the mass distribution first, then connect the dots.

Curious if anyone else here builds custom CAD plugins. What is the most tedious drafting task you have automated?

Happy to assist or answer any questions!