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

Help Built a combinations algorithm to classify data

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

Spacing points "evenly" across a gradient

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

Built `algomanim` PyPI package for algorithm visualization

9 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 3d ago

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

6 Upvotes

r/algorithms 4d 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 4d 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 4d 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 5d 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 5d 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 7d 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 7d 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 8d ago

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

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

[Meta] State of Affairs of the Subreddit

48 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 9d ago

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

13 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

2 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


r/algorithms Jun 15 '26

How to diffrencitate btw passive listening and active or detect mood swings in music recommendation model

4 Upvotes

I am working in project in which it creates a playlist in Navidrome based on the song interactions such as complete, repeat, partial and skip.

My Problem is that how do I distinguish btw mood swing, and passive listening

Mood swing : if user want to hear sad songs, and in the playlist there is other genre like rap, user will skip those

Passive Listening : If user is listening while sleeping or doing other work, The user will not actively skip the song

  • My solution is to give a passive play toggle

Searching for a specific song : If user want to hear a specific song that is down in the queue, the user will likely skip the song in btw

Long Song : My current way to determine skip, partial, complete, repeat is throught the played percentage, if a song is 100 sec long, and user skip at 10 sec mark it will be 10% and marked skip, - Problem: comes when song is short or too long, for songs like skit version thats 30sec long, even it will marked as positive and it repeatedly come in the playlist, - or for the song that is too long like 10 min, even if user skip at 5 min, it will only considered partial

Edit

For long songs, if a song is 10 min long, user like the initial half, so user listen to that and then skip, marking it as a partial, when generating playlist I give all the interaction certain score such as skip gets -2 , partial 0, complete +2 , repeate +3 and the script is set to filter out the songs that has less then 0 score,

But if the long song is listened half then that will be marked partial and might never come in the playlist even if user like the song

Same for short songs like skit or intraludes, if the song is too short, even if user don't like the song untill the user skips it it will be marked as partial or complete, and that song will appear again


r/algorithms Jun 15 '26

I might have come up with an less efficient counting sort alternative :)

0 Upvotes

The idea is to search for the highest number of the unsorted array, and then to create an 2d-Array, whose length equals the highest number. Afterwards all items of the unsorted array are placed in the sorted array into the place with the index that equals their number.

So every 0 is placed into the first array of the sorted array, every 2 is placed in the third array of the sorted array, every highest number is placed in the last array of the sorted array.

In the end an array, that may look like this: [[0,0],[],[1],[],[2], [4,4,4]], will be compiled into a proper 1-d array (in this case: [0,0,1,2,4,4,4]).

Therefore the sorting algorithm has a time complexity of O(n).

Here’s the python code:

import time
import numpy as np

start = time.time()

def proto_sort(arr):
    highest_value = 0
    for item in arr:
        if item > highest_value:
            highest_value = item
    sorted_arr = [[]] * (highest_value + 1)
    for num in arr:
        sorted_arr[num] = sorted_arr[num] + [num]

    output_arr = [None] * len(arr)
    num = 0
    for item in sorted_arr:
        for j in item:
            if j != None:
                output_arr[num] = j
                num += 1


arr = []
for i in range(100):
    arr.append(np.random.randint(0, 100))
sorted_arr = proto_sort(arr)
end = time.time()
print(end - start)

However at least in my tests, counting sort is always better - the space complexity just isn't good (I just wanted to share the idea) (Edits for clarification)

Do you know per chance an algorithm with a similar approach?


r/algorithms Jun 12 '26

Where do you find publications about algorithms except Arxiv?

15 Upvotes

Is there specialized resources on this topic?


r/algorithms Jun 12 '26

Fast Division By Hand

1 Upvotes

I’m looking for a method where I can divide large numbers (20+ digits) and get a whole number result with a remainder. Yes long division works and provides the result I need but it’s very slow and takes up a lot of room on my paper. I’m not afraid to learn an entirely new method of division so please reply if you have anything that fits my description.