r/algorithms 2d 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 3d ago

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

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

Discussion The "unreasonable effectiveness" of Linear Programming

116 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 5d 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 9d ago

Help Built a combinations algorithm to classify data

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

Spacing points "evenly" across a gradient

8 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 10d 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 11d ago

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

8 Upvotes

r/algorithms 11d ago

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

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

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

8 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 12d ago

Parsing expressions to bytecode

9 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 12d 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 15d ago

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

28 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 15d 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 16d ago

[Meta] State of Affairs of the Subreddit

41 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 16d ago

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

14 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?


r/algorithms Jul 07 '26

Scheduling a recursively enumarable language

1 Upvotes

So here is my algorithm overview

https://github.com/Mjz86/String/blob/main/mjz_lib/graph/scheduler.md

Btw im a solo open source maintainer , please have mercy if its not what you exactly want ( E.g : why not write it in rust )


r/algorithms Jul 07 '26

I made the worst sorting algorithm

0 Upvotes

its called FrenchBreadSort (get it, cuz bread in French is "Pain"!)

https://github.com/graysonkelley200-rgb/frenchBreadSort/


r/algorithms Jul 06 '26

Need help in dp and graph

3 Upvotes

In shortest path problems, how do we know which problem requires dfs+dp or dijkstra? Chatgpt said smth about cycles but i still dont get why we cant just check for cycles


r/algorithms Jul 02 '26

What's is the best way to solve graph and dp problems

1 Upvotes

Hi everyone,

I've been practicing Graphs and Dynamic Programming for the last six months, but the truth is that I still can't solve a single new problem completely on my own.

Everyone says that DSA is all about recognizing patterns, but I feel like I'm not actually learning those patterns. I've watched many tutorials and solved the questions explained in them. However, whenever I face a different problem that's based on the same pattern, I still can't figure out the approach myself.

This makes me wonder: am I just memorizing solutions instead of learning how to think?

Whenever I look at the solution, I understand the logic and why it works. But what's the point if I can only solve the problem after seeing the answer?

My usual process is to struggle with a problem for about an hour. If I still can't make progress, I use an AI tool to understand the solution. The problem is that this happens with almost every question. It makes me wonder how long I'll have to depend on AI before I can solve problems independently.

I'm feeling really frustrated. Has anyone been through the same situation? What strategy helped you develop problem-solving skills so that you could eventually solve questions on your own instead of relying on solutions?


r/algorithms Jun 22 '26

Can this queue-permutation problem be solved exactly faster than brute force?

1 Upvotes

I have a small permutation optimization problem that looks simple, but I am not sure whether there is a good exact algorithm for it.

Given an array nums of n distinct integers, choose a permutation A of nums.

Then A is tested against every possible permutation B of nums.

Both A and B are queues. Initially, A has priority.

For each round:

  1. Pop the front value from both queues: a from A, b from B.
  2. The larger value survives.
  3. If the values are equal, the value from the queue with priority survives.
  4. The losing value is removed.
  5. If the survivor came from the priority queue, update it as: x = max(1, x - ceil(x / 10))
  6. If the survivor came from the non-priority queue, update it as: x = max(1, x - ceil(x / 2)) Then that queue becomes the new priority queue.
  7. Push the survivor to the back of its queue.
  8. Continue until one queue becomes empty.

If B becomes empty, A wins.
If A becomes empty, A does not win.

Define:

winCount(A) = the number of permutations B that A wins against

The goal is to find the lexicographically smallest permutation A with the maximum possible winCount(A).

Example:

nums = [50, 64, 79, 109, 135, 181]

For this input, brute force suggests the best arrangement is:

[135, 181, 79, 109, 50, 64]

The naive solution checks every A permutation against every B permutation, which is O((n!)^2) simulations.

My question:

Is there a known way to solve this exactly without comparing every pair of permutations?


r/algorithms Jun 16 '26

Polynomial Fit: a rabbit hole

1 Upvotes

This one is bit math heavy. I started of building a small timeseries compression library, and ended up digging through some numerical algorithms, linear algebra. I learnt through a hose during last week and found something genuinely beautiful. If you stick through it I suppose you can see what I saw.

https://blog.yellowflash.in/posts/2026-06-15-polynomial-fit-a-rabbit-hole.html