r/algorithms • • 1d ago

Discussion This Week I Learned: October 16, 2026

2 Upvotes

This thread is meant for users to share cool recently discovered facts, observations, proofs, algorithms, or concepts that might not warrant their own posts. Please be encouraging and share as much detail as possible, as we’d like this to be a good place for people to learn!


r/algorithms • • Sep 10 '26

Discussion [Meta] AI Stuff on this Subreddit

17 Upvotes

Hi all, wanted to get some thoughts on AI related things. I know it's a polarizing topic:

1. AI-generated papers

We’ve had a noticeable number of blatant, poorly written AI slop “papers” recently. At the moment there is isn’t much activity over here so it’s possible to check them manually (and use feedback from comments). But I don’t really want the mods manually vetting every such post should there be an overwhelmingly large number of these submissions in the future.

Some subreddits only allow arXiv submissions and peer-reviewed papers. I for one am hesitant to do that here since I don’t want to restrict the dissemination of genuine work, even if it’s just on GitHub say.

AI is already producing STOC/FOCS level results, so ‘AI was used’ on its own should not be disqualifying. But of course, it should not come at the expense of the quality of the submission.

2. AI discussion megathread

Would people here be interested in a recurring AI megathread, similar to r/math’s, focused on algorithms and TCS? This could maybe include how people are using AI in research or work, AI-assisted results, a discussion about its impact on the field etc.

 

Thoughts, comments, concerns?

 

Best,

Phytor & the r/algorithms Mod Team


r/algorithms • • 8h ago

Help I can redo familiar problems, but new matrix and graph problems stump me. How do I improve?

6 Upvotes

I keep getting stuck on matrix, tree, and graph problems, even after spending time practicing. Matrix problems are especially difficult for me.

I can solve basic tree problems and problems I've solved before, but I struggle when I face something new.

What would you recommend practicing first? Is there a good progression from basic tree problems to matrix and graph problems that could help me build understanding instead of relying on having seen the problem before?


r/algorithms • • 8h ago

Help Audiobook recommendation from completion logs: what would you clarify before coding?

2 Upvotes

How would you clarify the requirements for this audiobook recommendation prompt before starting to code? The setting is a roughly 30-minute interview slot after behaviorals, so I'm also wondering whether the expectation is low-level design (LLD) rather than just an algorithm.

Prompt: Audiobook Recommendation System

Given a log of "audiobook completed" events, write code to implement an audiobook recommendation system. It should answer "What should I listen to next?" based on the listening patterns in the log.

For example, if many customers listened to BookA followed by BookB, then given BookA as input, the recommendation system should return BookB.

python logs = """ 2025-08-09T03:25:11Z,Customer1,BookA 2025-08-09T04:10:50Z,Customer2,BookB 2025-08-09T12:01:24Z,Customer2,BookC 2025-08-09T15:33:49Z,Customer3,BookB 2025-08-10T07:54:35Z,Customer1,BookB 2025-08-10T08:00:08Z,Customer4,BookD 2025-08-10T11:29:31Z,Customer3,BookE 2025-08-10T23:45:00Z,Customer5,BookF 2025-08-10T23:51:20Z,Customer6,BookB 2025-08-11T09:05:16Z,Customer1,BookC 2025-08-11T20:12:57Z,Customer3,BookA 2025-08-11T20:59:32Z,Customer7,BookB 2025-08-11T21:00:13Z,Customer2,BookB 2025-08-12T05:17:23Z,Customer1,BookB 2025-08-12T18:19:07Z,Customer1,BookC 2025-08-12T22:22:42Z,Customer5,BookE 2025-08-13T00:07:58Z,Customer7,BookG 2025-08-13T04:02:29Z,Customer6,BookE 2025-08-14T21:12:33Z,Customer3,BookG 2025-08-14T23:49:00Z,Customer1,BookF 2025-08-15T12:00:01Z,Customer3,BookC """

What I'm most interested in is the requirements discussion. "BookA followed by BookB" could mean the very next completion for the same customer, or any later completion. Would you also ask whether repeated listens count multiple times, whether to rank by events or distinct customers, and how ties or books with no follow-up should work?

Which questions would you prioritize within that time limit, and what implementation scope would you agree on before coding?


r/algorithms • • 1d ago

News Moni Naor wins the 2026 Knuth Prize

Thumbnail sigact.org
34 Upvotes

r/algorithms • • 2d ago

Help Does this sorting algorithm work?

0 Upvotes

I am trying to analyze a sorting algorithm that uses an alternating sorting pattern across three piles (Pile A, Pile B, Pile C). I want to see how this pre-sorting rule affects the balance and solvability of a partition problem.

The Algorithm Step-by-Step: Let S be a collection of 3N items with positive integer weights.

  1. The Pre-Sorting Sieve: For each step i from 1 to N, take the next 3 items from S and sort them by weight: Large, Medium, and Small.
    • If i is even: Add Large to Pile_A, Small to Pile_B, and Medium to Pile_C.
    • If i is odd: Add Small to Pile_A, Large to Pile_B, and Medium to Pile_C.
  2. The Partition Search: After all items are sorted, we look for an exact matching partition. We want to find a way to split the Medium items in Pile_C into two sub-piles, C_to_A and C_to_B, such that:
    • Every single element of Pile_C is placed exactly once into either C_to_A or C_to_B.
    • The Target Equation: Sum(Pile_A) + Sum(C_to_A) == Sum(Pile_B) + Sum(C_to_B) If a matching split is found, the program outputs "yes" and halts.

My Questions for the Board:

  1. Imbalance Bounds: Because the algorithm alternates assigning Large and Small items between Pile A and Pile B, the initial difference between their sums, |Sum(Pile_A) - Sum(Pile_B)|, stays highly constrained. If the initial item weights are randomly chosen from a uniform distribution, how do we write a formula for the expected variance of this difference as N grows?
  2. Phase Transition and Density: While it is easy to construct worst-case inputs where a perfect partition is completely impossible, what happens under typical conditions? Since Pile C accumulates N median elements (a linear capacity of O(N)) while the initial imbalance between A and B is tightly bound, does this system undergo a sharp statistical phase transition where a valid partition becomes almost certain for dense, random inputs as N approaches infinity?

I would love to see any formulas, recursive relationships, or references to similar 3-pile sorting partition problems! Thanks for any help.


r/algorithms • • 3d ago

Research/Papers Stop blind-guessing algorithms: Why allocating 1% of your compute budget to "Landscape Reconnaissance" yields 4.5x speedups in NP-Hard problems.

5 Upvotes

TL;DR: Instead of immediately throwing 100% of our compute budget at a solver and hoping for the best, inserting a lightweight "reconnaissance" pipeline to measure landscape ruggedness and constraint density (costing <0.5% of total time) can dictate exactly which algorithm to use, yielding massive wall-clock speedups.

Hey everyone,

I’ve been doing some deep research into how we handle the pipeline between "building a mathematical model" and "deploying a solver" for large-scale optimization problems (VRP, MKP, Scheduling, etc.).

It feels like the industry standard is still heavily reliant on trial-and-error: Should we use a Genetic Algorithm here? Simulated Annealing? Let's just run a grid search on hyperparameters and burn some AWS credits to find out.

I recently formalized a framework based on a very simple military philosophy: The scouts are the brain; the solver is the muscle.

Instead of blind deployment, I proposed a Dynamic Reconnaissance-Flattening (DRF) Pipeline. Before the main solver fires up, we send a tiny batch of "scouts" (e.g., 50 Sobol sampled points) to evaluate the loss landscape. We measure three universal metrics:

  1. Ruggedness
  2. Constraint Density
  3. Gradient Smoothness

Based on these metrics, the pipeline acts as a dispatcher, automatically assigning the correct algorithm and parameters.

Here are the actual benchmark results from the papers:

  • For Routing (VRP): By using the reconnaissance data to perform "Angular partition cutting" (flattening the terrain before solving), we saw a +74% performance improvement compared to raw solving.
  • For Multi-dimensional Knapsack ($n=5000$): Allocating just 0.5% of the compute budget to reconnaissance and dynamic resolution shifting resulted in a 4.5x wall-clock speedup and a 61% improvement in solution quality.

Why this isn't Snake Oil (The SAT Test):

The most important part of this pipeline is its discipline. When the reconnaissance scouts hit a Boolean Satisfiability (SAT) problem in the phase transition region, the pipeline doesn't try to aggressively smooth it out. It correctly diagnoses it as a "Hard Wall" (discrete cliffs), abandons the heuristic intervention, and hands it straight to CDCL solvers. It knows what it can't do.

I’ve published the complete theoretical taxonomy (dividing NP-hard problems into 7 boxes) and the DRF pipeline architecture as open-access whitepapers on Zenodo.

📄 Paper 1 (The Taxonomy & Reconnaissance): https://doi.org/10.5281/zenodo.19510539

📄 Paper 2 (The DRF Pipeline): https://doi.org/10.5281/zenodo.19600597

I’m currently working on turning this into a lightweight, open-source Python middleware (drf-scout). The goal is to let developers pass their objective function, have the middleware run the 1% reconnaissance, and automatically dispatch to the best open-source solver (like OR-Tools or PySAT).

I’d love to hear your thoughts. How do you currently handle algorithm selection? Do you rely on pure experience, or do you have any pre-solve diagnostic tools in your workflow?


r/algorithms • • 3d ago

Discussion Shell sort achieving N log N complexity?

0 Upvotes

I was looking through an open source package, that was written more than 20 years ago (and some of the code probably 30 years ago). The sort subroutines are proudly commented "N log N". But they look like old-school Shell sort, with gap halved each iteration. So I doubt the performance. Only that some of the data would be partly sorted, e.g. having patterns like 1,3,5,2,4,6. But on the other hand, a lot of the data would come in multiples of 1024 samples. And 2048 or 4096 is not good for Shell sort is it?


r/algorithms • • 4d ago

News BusyBeaver(10) exceeds Graham’s number

64 Upvotes

From Scott's blog: Jeffrey Ketchersid has used Claude Code agents to show that BusyBeaver(10) exceeds Graham’s number, beating the previous best result that BB(13) does so.

[I do not think this is independently verified yet]


r/algorithms • • 4d ago

Help Doubt in proof writing

2 Upvotes

For this problem -

https://cses.fi/ckvo8q5wh/task/3419

How can I go about proving that the solution is true for all N?

The solution by the way is simple - we just have to XOR the row and column indice values for each Aij entry. So, Aij = i ^ j. How can I prove this mathematically?


r/algorithms • • 6d ago

Research/Papers Implementation of Andreas Bjorklund's algorithm for determining hamiltonicity

18 Upvotes

Hello, I want to share a project that i've been working on for the last month or so. It's and implementation (from what i could find the only rn on the internet) of Andreas Bjorklund's theoretical algorithm for determining weather a graph is hamiltonian or not. The algorithm is revolutionary because it lowered the exponential part of the time complexity of Held-Karp which is the standard algorithm for determining weather a graph is hamiltonian, from O^*(2^n) to O^*(1.657^n) for general graphs(this is what i've managed to implement as of right not) and for bipartite its O^*(1.414^n).

It might have some logical errors, and could maybe be optimised but right now, as of writting this it is 4AM and i want to sleep.

link to paper: https://arxiv.org/pdf/1008.0541
link to the github repo: https://github.com/Ak0-m/Bjorklunds_algorithm_for_Hamiltonicity


r/algorithms • • 7d ago

Help I can't understand recursion

36 Upvotes

I have been trying to understand recursion for weeks now but I cannot understand it one bit. When it comes to dry running a piece of code, I can do it easily but solving a question with recursion stumps me immediately. I cannot make any logic other than finding out what the base case would be. If anyone has any word of advise, please share it!


r/algorithms • • 7d ago

Help Comparing two algorithms

0 Upvotes

I'm taking the Algorithms for Searching, Sorting, and Indexing course from CU Boulder on coursera. In one of their assignments there is a question as follows:

Algorithm X programmed by an "ace programmer" runs in time 2.5n4+3n3+1.4n+22.5n4+3n3+1.4n+22 for inputs of size nnn in the worst case. Another algorithm Y programmed by a novice for the same problem runs in time 2000n+10000 for inputs of size n in the worst case.

The following is true about the problem statement:

It is possible for some input of size 100 that algorithm X is faster than algorithm Y.

At small inputs such as 1 or 2, algorithm X is faster than algorithm Y. But when plugging in n = 100, algorithm X comes out much, much larger than algorithm Y.

So how can that statement be true?

Thank you for your time helping me :)


r/algorithms • • 8d ago

Discussion This Week I Learned: October 09, 2026

7 Upvotes

This thread is meant for users to share cool recently discovered facts, observations, proofs, algorithms, or concepts that might not warrant their own posts. Please be encouraging and share as much detail as possible, as we’d like this to be a good place for people to learn!


r/algorithms • • 8d ago

Resource Essential Data Structures and Algorithms for Hackers

0 Upvotes

I created this blueprint for myself, then i thought, why not share with others? Maybe this will be useful to someone, so i started sharing work here.

Core Data Structures

Arrays & Strings: Contiguous blocks of memory. Crucial for understanding index manipulation, memory offsets, and manual buffer handling.

Pointers & Dynamic Arrays {std::vector**}:** Vital for managing heap memory directly, resizing buffers, and understanding how raw data flow under the hood.

Linked List (Singly & Doubly): Nodes containing data and memory addresses. Essential for mastering pointer manipulation, dynamic memory allocation, and breaking away from contiguous memory limits.

Stacks & Queses: Last-In-First-Out (LIFO) and First-In-First-Out (FIFO) structures. Essential for tracking execution contexts, implementing custom commands shells, and managing buffers or task loops.

Hash Tables/ Hash Maps {std::unordered_map}: Key-value stores powered by hashing functions. Critical for achieving O(1) average-time look-ups, frequency counting, and symbol table tracking.

Trees (Binary Trees & Binary Search Trees): Hierarchical nodes used for recursive data organization, directory structures, and fast searching.

Heaps/ Priority Queues: Complete binary trees where parent nodes outrank children. Essential for scheduling, greedy algorithms, and finding minimum/maximum elements efficiently.

Graphs (Directed/Undirected): Nodes connected by edges. Fundamental for modeling networks, state machines, dependency resolutions, and path finding.

Tries (Prefix Trees): Specialized trees optimized for prefix-based string searches, autocomplete, and lexical analysis.

Essential Algorithms

Asymptotic Analysis (Big-O Notation): Evaluating time and space complexity to understand how code scales under heavy input sizes.

Searching Algorithms: Linear search and Binary Search (critical for cutting search spaces down logarithmically).

Sorting Algorithms: Merge Sort, Quick Sort, and understanding comparison-based sorting efficiency (O(n \log n)).

Recursion & Backtracking: Breaking problems down into self-referential sub-problems and exploring state spaces systematically (used heavily in parsing and combinatorial search).

Two Pointers & Sliding Window: Array/string manipulation patterns used to optimize nested loop bottlenecks down to linear time.

Graph Traversals (BFS & DFS): Breadth-First Search and Depth-First Search for exploring network nodes, detecting cycles, or tracing paths.

Shortest Path Algorithms: Dijkstra’s Algorithm and Bellman-Ford for weighted graph navigation.

​Greedy Algorithms & Dynamic Programming: Making locally optimal choices vs. breaking problems down into overlapping sub-problems with memoization to optimize multi-stage decisions.

Conclusion

I hope this was helpful for you. It was just simple a blueprint to start things out. Maybe i will explain these concepts one by one in simple way, or you can check out other resources — there is plenty of learning materials out there.

Keep going, even if it doesn’t make sense .

— x86owl medium-blog-post


r/algorithms • • 9d ago

Resource Built an interactive visualizer for AVL tree rotations, Dijkstra's algorithm, and dynamic arrays

1 Upvotes

Hey everyone!

While studying data structures, I always felt that static diagrams didn't quite capture how dynamic invariant rebalancing and memory reallocation work under the hood.

So I built an interactive state visualizer to see the step-by-step mechanics in action:

👉 Live App: https://data-structure-visualizerr.vercel.app

What's currently implemented:

• Self-balancing AVL Trees (dynamically triggers LL, RR, LR, and RL rotations with live balance factors)

• Weighted Graphs (Dijkstra's shortest path with real-time distance-vector edge relaxations)

• Dynamic Array buffer resizing (visualizing capacity doubling C -> 2C and amortized O(1) analysis)

• Trie (Prefix Tree) with live autocomplete predictions

I'd love your feedback on the animation pacing, clarity of the mechanics, or any edge cases you notice!


r/algorithms • • 10d ago

News Unique Games Conjecture, RL= L claimed to have been proven by OpenAI

Thumbnail github.com
338 Upvotes

OpenAI just released this on Github. It seems like the rumors of the Unique Games Conjecture and RL = L were indeed true. There's also a lot of other stuff in there which i haven't looked at yet.

Regardless of one's views on AI, it's safe to say TCS is truly facing a watershed moment...


r/algorithms • • 10d ago

News Truly subquadratic 3SUM and truly subcubic APSP

Thumbnail arxiv.org
80 Upvotes

r/algorithms • • 13d ago

Discussion This Week I Learned: October 03, 2026

17 Upvotes

Inspired by r/math, I’m starting a similar recurring weekly thread here.

This thread is meant for users to share cool recently discovered facts, observations, proofs, algorithms, or concepts that might not warrant their own posts. Please be encouraging and share as much detail as possible, as we’d like this to be a good place for people to learn!


r/algorithms • • 16d ago

Discussion Looking for people who are interested in discussing problems of an algorithmic and computational flavor, is this the place?

29 Upvotes

I've been wanting to organize a problem solving seminar for computer science as a volunteer activity. The way I was thinking of it working would be that the problems would be curated to be meaningful exercises. People would tinker with the problems on their own for a month, then at the end there would be a gathering where people discuss approaches and extensions. Potentially if there was anything interesting, one could write it up.

This seems like a good forum but I'm basically looking to help organize something a little more structured in the way of an online correspondence club or "magazine", even. People can send in interesting problems, I or others can serve as editors, we send out the problems, there would be some offline mulling and finally we would congregate and maybe put together a resolution of sorts for the next edition. I would like the emphasis to really be on the personal, individual, and/or collaborative, collective experience, though, and less on putting out polished products or work.

I'm not too aware of other existing models that do this besides PagedOut!, which is outside of my niche. But I'm interested in volunteering my time and resources for such an activity.

The only thing is I do more data processing than pure theory, I would say. I'm looking for a similar community or at least one that is open to those sorts of topics.

Thoughts or pointers? Criticisms on why this sort of idea lacks momentum? Thanks in advance.

UPDATE 10/02: see this comment to ask to be invited to the Discord server!


r/algorithms • • 15d ago

Discussion IA neuro-symbolique sur le problème du voyageur de commerce

0 Upvotes

J'ai conçu une IA neuro-symbolique avec le benchmark ARC AGI 2 comme banc d'essai (dépôt aicpp sur GitHub : https://julien-livet.github.io/aicpp/). J'envisage d'appliquer mon approche au problème du voyageur de commerce. Qu'en pensez-vous ?


r/algorithms • • 20d ago

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

3 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 • • 19d ago

Help I found most irritating question on codechef

0 Upvotes

Partition Score

Given an array AA of size NN, we must partition the array into 22 disjoint subsets S1S1​and S2S2​such that every element of AA belongs to either S1S1​or S2S2​. Further, we are given a parameter KK and must ensure ∣S1∣≥K∣S1​∣≥K and ∣S2∣≥K∣S2​∣≥K, i.e. both S1S1​and S2S2​have size at least KK.

We define score=min⁡(S1)+max⁡(S1)+min⁡(S2)+max⁡(S2)score=min(S1​)+max(S1​)+min(S2​)+max(S2​), where min⁡(S1)min(S1​) is the minimum element present in S1S1​, and the other terms are defined similarly.

Compute the maximum scorescore in any valid partition.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line contains NN and KK - the size of the array and the parameter
    • The next line contains NN integers - A1,A2,...,ANA1​,A2​,...,AN​.

Output Format

For each test case, output on a new line the maximum scorescore in any valid partition.

Constraints

  • 1≤T≤1041≤T≤104
  • 2≤N≤2⋅1052≤N≤2⋅105
  • 1≤K1≤K and 2⋅K≤N2⋅K≤N
  • 1≤Ai≤1061≤Ai​≤106
  • The sum of NN over all test cases does not exceed 2⋅1052⋅105

Sample 1:

Input

Output

3
4 1
3 1 2 5
6 3
1 2 3 4 5 6
5 2
1000000 1000000 1000000 1000000 1000000


14
15
4000000

Explanation:

Test Case 1 : The optimum partition is :

  • S1=[1,2,3]S1​=[1,2,3]
  • S2=[5]S2​=[5]

min(S1)=1min(S1​)=1, max(S1)=3max(S1​)=3, min(S2)=5min(S2​)=5, max(S2)=5max(S2​)=5. Adding them up, we get 14


r/algorithms • • 20d ago

Help Combinatorial method for generating non-repeating 22-question trivia rounds from unequal category pools?

3 Upvotes

I’m building a trivia game. I have about 40 categories, and each category has between 20 and 80 questions. All questions are about the same difficulty. Each round gives the player 22 questions.

I want a player on a streak to keep getting new questions and not see the same question again across rounds, for as long as possible. If perfect non-repeating eventually becomes impossible, I want to minimize repeats and still keep categories reasonably balanced.

How should I approach this mathematically? How many non-repeating 22-question rounds can I guarantee? What is a good method for choosing questions each round? I’m looking for a simple model, algorithm, or known scheduling/combinatorics method.

This is my game if you need tge reference https://cluebolt.com/


r/algorithms • • 23d ago

Discussion Layperson question

15 Upvotes

I'm a non-major currently taking an intro cs class, but it's mostly practical, project-based Python stuff -- no theory. Which tbh I'm a little sad about.

I was wondering: Are there any algorithms/functions that are executable by infinitely many non-trivial, non-redundant programs? Does any given algorithm/function fit this description?

Math example:
The user inputs a radius R, from which the program P outputs the area A of the resulting circle.

You could plug it into the standard formula:

P1 = A(R) = πR^2

...

Or integrate:

P2 = A(R) = ∫₀²ᵖⁱ ∫₀ᴿ r dr dθ

...

et cetera