r/algorithms

Pathfinding algorithm for walking through a grid

Hello, I'm not an expert on data structures and algorithms so sorry if this is a very banal question. I'm looking for a pathfinding algorithm, it doesn't have to mathematically perfect and return the shortest possible path in every case but it should be reasonably close and lightweight cause I plan to run it thousands of times. Here's the problem statement:

There's a rectangular 2D grid consisting of empty and filled cells and a starting point which may be anywhere on that grid. I want to generate a path which goes through all the filled cells atleast once and takes the least amount of steps. Each move forwards/backwards in a straight line takes one step while taking a turn takes another step. So for example if I decide to walk 5 cells east/west from the start and then walk 5 steps north/south it will take 11 steps in total.

reddit.com
u/angryvoxel — 8 hours ago

My interactive graph theory website just got a big upgrade!

Hey everyone,

A while ago I shared my project Learn Graph Theory, and I’ve been working on it a lot since then. I just pushed a big update with a bunch of new features and improvements:
https://learngraphtheory.org/

The goal is still the same, make graph theory more visual and easier to understand, but now it’s a lot more polished and useful. You can build graphs more smoothly, run algorithms like BFS/DFS/Dijkstra step by step, and overall the experience feels much better than before.

I’ve also added new features and improved the UI to make everything clearer and less distracting.

It’s still a work in progress, so I’d really appreciate any feedback 🙏
What features would you like to see next?

reddit.com
u/xain1999 — 4 days ago

Top Down Red-Black Deletion for the Masses

If like me, you have been frustrated by the lack of an easy to understand top down deletion algorithm that is not for left leaning red black trees, than allow me to present to you a little write up i made, with the hopes of taking some of the mystery out of this somewhat legendary deletion algorithm.

Top Down Deletion in Red Black Trees

reddit.com
u/drinkcoffeeandcode — 15 days ago

Sortedness?

Is there any way to look at a list and measure how sorted it is?

And is there a robust way to prove that any algorithm to execute such a measurement must necessarily require n log n since the fastest sorting algorithm requires n log n?

And a final variant of these questions: is there any way to examine a list in o(n) and estimate which n lg n algorithm would sort with the least operations and likewise which n^2 algorithm would sort with the least operations?

reddit.com
u/JasonMckin — 25 days ago

Longest Common Substring: from Brute Force to Sparse DP

I wrote an explanation about a sparse dynamic programming (DP) algorithm, that I have developed, for longest common substring (not subsequence!). I follow the roadmap:
basic intuitions -> brute force -> DP -> sparse DP

Hopefully, it is of educational value. This is the link to the github repo:
https://github.com/O-logN/SparseDP-LCSubstr
the explanation is in the github page.

About complexity
This sparse DP algoritm is an "evolution" of a DP algorithm that is sometimes found on the internet. It requires O(n + m + #(x,y)) time and O(min(n,m)) space, given two strings x and y of length n and m respectively, where #(x,y) denotes the number of index pairs (i,j) such that x[i]=y[j].

In the github page, i also mention two further optimizations.
Help with benchmarks (check the github page intro) would be appreciated.

u/RedBoilingSoup — 20 days ago

Best 64-bit key/value HashMap for cache-friendly access

I’m looking for guidance on designing or choosing a high-performance hashmap with the following characteristics:

  • Key: 64-bit integer
  • Value: 64-bit integer
  • Cache line: 128 bytes
  • Goal: Accessing a key should automatically bring the corresponding value into cache (implicit prefetching)
  • Performance: Extremely low latency, minimal cache misses

I know that some C++ libraries like flat_hash_map or robin_hood::unordered_map achieve this by storing key/value pairs contiguously in memory and using open addressing instead of chaining.

Questions:

  • What is the most cache-friendly hashmap design for 64-bit key/value pairs?
  • Are there alternatives to open addressing that achieve similar cache performance?
  • Any practical advice or references for hashmaps optimized for 128B cache lines?

Looking for insights from anyone who has built or benchmarked ultra-fast hashmaps with minimal cache misses. Thanks!

reddit.com
u/ANDRVV_ — 26 days ago

DevOps Engineer trying to learn DSA from scratch – where to start?

I’m currently working as a DevOps Engineer and want to upgrade my skills by learning DSA.

I have basic knowledge of C++ (syntax, loops, classes, structs), but I haven’t used STL much. My main goal is to build strong problem-solving and logical thinking skills, kind of like starting fresh.

I have a few questions:

  1. Should I first focus on learning C++ properly (especially STL), or start DSA alongside it?
  2. What would be the best roadmap for someone like me (working professional, not a full-time student)?
  3. How do I actually build logical thinking for problem solving? I often understand concepts but struggle to apply them.
  4. Any recommended resources, platforms, or daily practice strategy?

Would really appreciate guidance from people who transitioned into DSA while working full-time.

Thanks!

reddit.com
u/Iwillhelpyou_ — 1 month ago

Algorithm to find mark nodes in graph?

Hi l everyone,

I am trying to come up with an algorithm in which given an directed graph it marks certain node to be let's say checkpoints.

I define the nodes to be critical as that using the logs at these points I can reconstruct an exact path.

Let me clarify on its application, suppose I'm trying to log values in a method and I create a callgraph of the entire application ( for simplicity assume there are no callbacks or interrupts) now given logs at the checkpoint. I must be able to generate execution tree of the methods.

I want to minimize the logs but still be able to reconstruct the execution path taken.

Help me with which concepts should I look into.

reddit.com
u/Xar_outDP — 29 days ago
▲ 15 r/algorithms+1 crossposts

What are the best sorting algorithms for arrays with small-varying values and many repetitions with the fewest possible accesses to the array cells?

For example I need to sort this array:

-1,0,2,0,1,3,0,-2,1,0,3,-3

Constraints: minimum arrays accesses

No constraints on computing time

reddit.com
u/Chance_Building_6159 — 1 month ago

Preprint: Knowledge Economy - The End of the Information Age

I am looking for people who still read. I wrote a book about Knowledge Economy and why this means the end of the Age of Information. Also, I write about why „Data is the new Oil“ is bullsh#t, the Library of Alexandria and Star Trek.

Currently I am talking to some publishers, but I am still not 100% convinced if I should not just give it away for free, as feedback was really good until now and perhaps not putting a paywall in front of it is the better choice.

So - if you consider yourself a reader and want a preprint, write me a dm with „preprint“.. the only catch: You get the book, I get your honest feedback.

If you know someone who would give valuable feedback please tag him or her in the comments.

reddit.com
u/thomheinrich — 1 month ago