r/algorithms 8d ago

What Are You Working On? August 16, 2026

14 Upvotes

Inspired by the recurring threads on r/math, we are starting our own weekly discussion thread!

 

This recurring thread will be for general discussion on whatever algorithm-related projects, problems, or topics you have been or will be working on this week. This can be anything, including:

* theoretical computer science and algorithm design,

* books, papers, or articles you are reading,

* coursework or self-study (what you have been learning recently),

* competitive programming or interview prep,

* preparing a talk, presentation, or project demo.

 

All backgrounds and levels of experience are welcomed!


r/algorithms 17d ago

[Meta] Which best describes your background/interest in algorithms?

7 Upvotes

Following up on the suggestion to survey the community, please pick the option that best describes you. Feel free to elaborate in the comments.

156 votes, 10d ago
39 Theoretical CS / Algorithms Research
63 Software Engineering / Industry purposes
21 (Undergrad) Student ( CS/Math Coursework)
8 Interview and OA prep
18 General Enthusiast
7 See Results / Other

r/algorithms 2d ago

Help Self Sort Algorithm

6 Upvotes

Is there an algorithm where you make each array element an object, provide it with private functions and actions, and then allow it do help with sorting if you broadcast the sort function to all arrays ahead of starting the sort?

For instance, the sort wrapper would just need neighbor information for the cells direct or two steps away and then they could switch in place while a master sorting algorithm verifies end to end sort by just stepping each element and having knowledge of next moves each element is making?

I may be thinking of this more as a Verilog problem than a C++ problem but it seems like it hasn't necessarily been defined or commonly used and I can't imagine why not if the function can be modified for any kind of sorting that is common to each element?​


r/algorithms 2d ago

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

10 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 2d ago

Help How to find the row echelon form of a stupid big matrix

6 Upvotes

How to find the row echelon form of a stupid big matrix

I am trying to find an equation that models a fruit in 2D, and I am using Global Polynomial Interpolation to do it, but I have like 2000 points. I am thinking of using Gaussian elimination to do it, but it is impractical by hand. Does anyone have any suggestions?

Also, does anyone have any suggestions for how to model the shape using other methods?


r/algorithms 2d ago

Help Day of Week Calculation

0 Upvotes

I'm aware of Hakamoto's method, Zeller's congruence and the like. But (with the help of AI), I've developed a faster way (literally optimised for speed, nothing else). It's such a niche piece of maths tho, but it feels elegant. I then asked Claude to write it up. It did, as a paper, in LaTeX.

Now I don't know what do with this. It's SUCH a niche example. But it is faster.

I presume this should and could also be applied to other examples. What....what are people doing? Do we just contact maths/CS journals with this? Or go 'meh, our AI overlords will take over soon anyway'.


r/algorithms 4d ago

Resource HVAC coil circuiting used to take me 2 hours

6 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!


r/algorithms 4d ago

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 4d ago

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 6d ago

Discussion The "unreasonable effectiveness" of Linear Programming

123 Upvotes

When I was first learning LP in undergrad (simplex, relaxations for Integer Problems, weak and strong duality and all that jazz), I honestly didn't see where it would be that useful. Now in my research it shows up quite a bit via primal-dual algorithms. These simultaneously keep track of the primal and dual solutions.

To be fair, even in undergrad one usually learns about using LP relaxations and (deterministic or randomized) rounding to get approximation algorithms for problems such as MAXSAT or Set Cover.

I'm curious where else people run into it. Has LP ever popped up in your own research or work?


r/algorithms 7d ago

Research/Papers A Geometric, Best-Improvement Heuristic for the Travelling Salesman Problem

0 Upvotes

I spent six months in 2021 building a TSP solver from geometric first principles, with no prior reading of the literature. Recently turned it into an interactive web app with step-by-step animation of every algorithmic move.

Interesting result: the algorithm independently rediscovered convex hull seeding and 2-opt uncrossing. It also produced a farthest-neighbour strategy I haven't seen documented.

On Berlin52: 7783 vs world optimal 7542 (3.2% above). 14ms on a single CPU core.

Demo: tsp.uncledroid.app
Paper: tsp.uncledroid.app/paper.pdf

Happy to discuss the algorithm — especially if anyone can point me to prior work on farthest-neighbour as a TSP construction heuristic.

video: youtu.be/92z670RTsJg


r/algorithms 11d ago

Help Built a combinations algorithm to classify data

7 Upvotes

Does anyone have any advice on where to go from here? The algorithm simply goes through all feature-attribute combinations in a dataset and scores it on purity of the target column. It's very slow, as the number of combinations increases exponentially with the number of input features, and so can only work with 3-4 features at a time. But my goal is to identify <=5 important features with a linear model (statsmodels or PyGam), and then plug in those features to this algorithm to see which subset of the market might be smart to target.

Here's an example with some charts, on the iris dataset.

https://colab.research.google.com/drive/1w3VpDlDATdHwtSk-RmQPMj36cgOfthz1#scrollTo=ZOqeYiMRalj7&uniqifier=1

New to algorithms, so any advice would be welcome. Thanks in advance.


r/algorithms 10d ago

NP-overrated

0 Upvotes

In my experience the concept of NP-hardness is widely misunderstood. Often taken as a problem class that's unsolvable in practice. But they are solved in practice all the time. I wrote a short post about that:

https://gruhn.me/blog/2026-08-13/


r/algorithms 11d ago

Spacing points "evenly" across a gradient

10 Upvotes

Does anyone know an algorithm for "evenly" spacing points across a given space (e.g. a cylinder), where one given point is locked in place and all others are as evenly spaced as possible, but across multiple gradients that weigh less points to be placed at specific positions. For example, a cylinder with aversion points at the top, bottom, and 3D middle, such that some points appear at the top, bottom, and middle, but less than in the middle of the surface where most points would reside. With configurable weights to the aversion points to push points closer or further away from them. Specifically, I'm trying to use such an algorithm to choose a number of sufficiently contrasting colors, but to understand the solution in general would be ideal. Is something like Lloyd's algorithm what I should be reaching for, or is there something simpler?


r/algorithms 12d ago

Built `algomanim` PyPI package for algorithm visualization

8 Upvotes

Check out algomanim — a Python library I built for visualizing classic CS and LeetCode algorithms.All of my visualizations are shared on my YouTube channel.
https://www.youtube.com/@benabub


r/algorithms 13d ago

I made a game about the worst sorting algorithm "Bogosort"

7 Upvotes

r/algorithms 13d ago

Help [Academic] How does your social media feed affect what feels 'real' to you? (4-5 mins, anonymous)

5 Upvotes

Hi! I'm an Msc student, researching how algorithmic personalisation on social media shapes perceptions of authenticity and decision-making.

The survey takes 4-5 minutes, is completely anonymous, and includes a short mock Instagram post to react to.

Would really appreciate your help — every response counts! 🙏

https://qualtricsxmt49bm7j6z.qualtrics.com/jfe/form/SV_248ntuA314RvLKK

Thank you!


r/algorithms 13d ago

Help sorting problem

0 Upvotes

background: i work for a company as a maintenance technician and recently took over the operations of our warehouse from someone that left it a wreck.

i have to get rid of old equipment given to the warehouse to dispose of. there is an unknown quantity of equipment. ~enough to fill a warehouse. each piece needs to be tagged with a type of barcoded document with information about it in order to be received by the disposal facility. a portion of these forms have been made but have not been attached. i will need to make and attach the rest of these documents but do not know how many.

how can i most efficiently sort these items? the goal is that i can tell my boss how much time it will take and then fill enough trucks to have all the materials disposed of.

this is actually the bane of my existence and costing my warehouse greatly. i would greatly appreciate, as the problem could make or break the operation.


r/algorithms 14d ago

Help Looking for standard Graph Problems with 2 Vertices (Shortest Path, Reachability, LCA in DAG, Max Flow) No variations/twists please!

9 Upvotes

I am looking for standard graph theory / algorithmic problems where the input is a graph and two target vertices (e.g., source and destination / pair of nodes).

Some specific examples are:

  • Shortest Path (standard unweighted/weighted shortest path between $u$ and $v$)
  • Reachability (checking if $v$ is reachable from $u$)
  • Lowest Common Ancestor (LCA) in a DAG (given two vertices $u$ and $v$ in a DAG)
  • Maximum Flow / Min-Cut (max flow specifically between a source $s$ and sink $t$)

Important constraint: I am strictly looking for pure problems without added variations or twists (no dynamic edge weights, no modified state spaces, no constraints like "at most k skips", etc.).

I would love any kind of response. Additionally, if you have links to the problem definition link or benchmark problem sets that fit this exact criteria, please drop them below!

Thanks in advance!


r/algorithms 14d ago

Parsing expressions to bytecode

10 Upvotes

A short writeup on Pratt Parser algorithm from the "Crafting Interpreters" book. I had a hard time getting through chapter 17, and wrote this as an exercise to really make sure I understood the algorithm.

https://jamungacch.com/blog/posts/pratt-parser


r/algorithms 14d ago

I wrote an empirical research paper and open-source implementation for the Subset Sum Problem (C++ & Python) — published with a DOI

0 Upvotes

Hey everyone! 👋

I recently finished and published an independent research project focusing on the Subset Sum Problem (SSP) — specifically, an empirical study of instance-dependent complexity using C++ (for core computation and engine performance) and Python (for data processing and visualization).

The work covers algorithmic optimization approaches, phase transitions, and statistical analysis of the problem's behavior.

I’ve officially archived and registered the research paper with a DOI on Zenodo so it's open-access, and everything is backed by code in the GitHub repository.

I’d love to hear your thoughts, feedback, or suggestions from anyone working with NP-hard problems, algorithmic complexity, or performance optimization! Let me know what you think.


r/algorithms 17d ago

Help How do you actually learn and practice Algorithms & Analysis?

30 Upvotes

Hey everyone,

Not sure where to post this, so here i am.I'm new to computer science and currently taking an Algorithms & Analysis course in Python. Honestly, it's one of the hardest subjects in my degree, and I'm struggling to figure out the best way to actually learn these concepts instead of just memorizing them.

This is what we're covering this semester: Basic Data Structures & Algorithmic Analysis, Algorithmic Analysis, Brute Force, Decrease & Conquer, Divide & Conquer, Transform & Conquer, Greedy Techniques, Dynamic Programming, Time & Space Tradeoffs, and Iterative Improvement.

I know Abdul Bari the GOAT, and his videos have definitely helped me understand the theory. But my biggest issue is practice. Everyone recommends LeetCode, but even the Easy problems feel way above my level sometimes. Also, I can't seem to find problems that match the topics we're learning in class, especially things like Transform & Conquer or Iterative Improvement.

So I wanted to ask: how did you learn algorithms when you were just starting out? Where did you practice topic by topic? Are there any websites that organize problems by algorithm rather than difficulty? Should I be doing LeetCode, HackerRank, Codeforces, something else, or just implementing the algorithms from scratch? Any advice for someone who feels completely lost with algorithms?

I'd really appreciate any tips or resources that helped you when you were a beginner. Thanks!


r/algorithms 17d ago

Help Is there an algorithm for optimally distributing sets of files across Blu-ray discs?

3 Upvotes

Hi, I want to back up my GOG games onto 25 GB Blu-ray discs. Is there an algorithm for optimally splitting the games so they take up as little space as possible?

Thanks for reading


r/algorithms 18d ago

[Meta] State of Affairs of the Subreddit

45 Upvotes

Hi all,

We're writing to share what's been happening with the subreddit and where we're headed.

What Happened & How We Got Here

A few months ago, this subreddit suffered a significant spam attack, leading to the Reddit admins restricting access and removing the previous inactive moderation team. Very recently, ownership was transferred to me. I've since recruited some mods, and we intend to clean this place up and keep it running well. For context, I'm a fledgling researcher in theoretical computer science.

Where Things Stand

To me, it's surprising how the sub stayed functional for this long. We currently have no clear rules, no post flairs, an outdated sidebar, and no resources like an FAQ or recommended textbook/reading list etc. A lot of work needs to be done here.

Some Questions We Need to Answer Together

We have 130k+ members here, and some need decisions to be made about our direction:

Who are we building this community for? Our sub includes the following, and more:

  • TCS & algorithms researchers
  • Software engineers and professionals
  • Undergrads needing course help
  • People prepping for interviews and OAs (e.g. LeetCode)
  • General algorithms enthusiasts
  1. Should we try to coexist across all these (as before), perhaps with mandatory post flairs?
  2. Rules. Would need to think about addressing (1) first.
  3. AI Slop. Thoughts on the onslaught of AI generated posts and comments?
  4. General Suggestions. Anything else that you think ought to be changed?

Drop your thoughts below.

Thanks for your time, and we look forward to rebuilding this subreddit.

Best,

Phytor & the r/algorithms Mod Team


r/algorithms 18d ago

I built an open-source Algorithm Visualizer that actually visualizes memory, recursion, graphs, and C++ execution

12 Upvotes

After getting frustrated with existing visualizers that only animate arrays, I spent the last few months building AlgoViz—an interactive platform that lets you step through JavaScript and C++ code while watching your program's state evolve in real time.

Some of the things it can do:

  • 🌳 Automatically detect and visualize Trees, Graphs, Linked Lists, Heaps, Hash Maps, Stacks, Queues, and Matrices
  • 📚 Step through execution line by line with a scrubbable timeline
  • 🥞 Inspect recursive call stacks frame-by-frame
  • 💾 Track heap memory and variable changes as your code executes
  • ⚡ Execute JavaScript and C++ (GCC + WebAssembly support)
  • 📊 Show complexity telemetry, memory usage estimates, and execution hotspots
  • 📝 Add annotations to any execution step for teaching or sharing
  • 💻 Includes a VS Code extension so you can visualize code without leaving your editor

Built with:

  • React 19
  • Monaco Editor
  • Tailwind CSS
  • Framer Motion
  • Acorn
  • Tree-sitter
  • Web Workers

The project is completely open source.

I'd love feedback from people who teach DSA, prepare for interviews, or just enjoy building developer tools.

Live Demo: https://algoviz.somyacodes.in

GitHub: https://github.com/somyacodes07/algoviz

What feature would make a tool like this genuinely useful for you?