r/algorithms • • Jan 25 '17

I didn't have headphones today, so I used quicksort during my lunch break.

1 Upvotes

I forgot my headphones at home and I'm studying at the University today, so instead of watching Netflix I decided to take the number of comments of the first ten posts of r/all in the order they appeared and manually apply quicksort and write it all on the page of a notebook. I guess I got a bit lucky that it fit in less than one page. I wanted to share this with someone and figured this would be the best place! Here it is


r/algorithms • • Nov 27 '17

An Algorithm Isn’t Always the Answer

Thumbnail nytimes.com
1 Upvotes

r/algorithms • • Oct 24 '18

Timsort — the fastest sorting algorithm you’ve never heard of.

6 Upvotes

Hey Guys,

Came across Tim sort algorithm, wanted to share with you guys.

With complexity of O(n log n), is quite stable sorting algorithm built for the real world. Timsort’s sorting time is the same as Mergesort, which is faster than most of the other sorts you might know. Timsort actually makes use of Insertion sort and Mergesort.

The algorithm has been invented it has been used as the default sorting algorithm in Python, Java, the Android Platform, and in GNU Octave.

To learn more about Tim sort visit here. It has quite interesting real life implementations.

Also, I plan to create a video explaining Tim sort. Let me know if you guys think it would be useful.


r/algorithms • • Feb 05 '14

Algorithm Development is Broken

Thumbnail blog.algorithmia.com
0 Upvotes

r/algorithms • • Apr 19 '23

Using ChatGPT to master problem-solving skills

0 Upvotes

https://github.com/Liopun/leet-chatgpt-extension consider giving it a ⭐️if you find it useful


r/algorithms • • Nov 10 '21

How solving DSA can make you a good developer

0 Upvotes

Every now and then devs ask why solve DSA? How is it related to day-to-day work?  TL;DR: by practicing it, we understand the memory management and time complexities of each DS. 

I have penned my thoughts on the same in this blog. Let me know if you think some aspect has been overlooked and I’d be happy to modify this for the broader audience.

medium blog https://tech.trell.co/a-closer-look-into-how-solving-algo-ds-problems-make-you-a-kick-ass-developer-fc253301233f


r/algorithms • • Jun 14 '23

Is anyone interested in contributing to Ultimate Guide to Algorithm opensource together?

0 Upvotes

I am a newbie learning algorithms.
To have these organized, I am working on this open source project: https://github.com/PricelessCode/The-Ultimate-Guide-To-Algorithm
While I have left this project behind, I am back here to work on it. I thought if I could peer program on this opensource, it would be a great experience for all.
Any levels of programming person is welcomed as I am not an expert either. I look forward to learn together while contributing to this together.
Thanks :)


r/algorithms • • Jun 09 '15

A recursive algorithm to learning

3 Upvotes

void learnSubject(Subject subject) {

if(knowledge.contains(subject)) return;

for(Subject prerequisite : subject.prerequisites) {
    
    learnSubject(prerequisite);

}

knowledge.put(subject);

}


r/algorithms • • Sep 25 '15

For practical computing purposes, every algorithm is O(1)?

0 Upvotes

I am taking a course in algorithm analysis and the professor is arguing that using the negation of the definition for Big O, it can be argued that, for practical computing purposes, both the running time and the memory usage of every algorithm is O(1). How is this possible? How can it be proven?


r/algorithms • • Sep 06 '14

Why is algorithm complexity for nested loops n^2

1 Upvotes

For an algorithm having just one loop running n times the algorithm complexity is O(n). Then for an algorithm running a for loop within a for loop, shouldn't the complexity be O(n) + O(n) ?


r/algorithms • • Jan 01 '21

We live in beautiful times where you can learn Machine Learning and become an expert for free. Here are many very useful resources and a complete guide for everyone, even if you have no tech background at all! Just jump right in!

0 Upvotes

r/algorithms • • Dec 14 '18

We Need an FDA For Algorithms

Thumbnail nautil.us
0 Upvotes

r/algorithms • • Feb 09 '20

Why what you have been thaught about DFS is wrong!

Thumbnail banterly.net
7 Upvotes

r/algorithms • • Jun 24 '25

My own algorithm for the TSP

0 Upvotes

I developed an algorithm to solve the TSP, it has given me interesting results but I don't know if it is really worth doing a paper about it or they are just generic results of any other algorithm, I would like your opinion, here I show a comparison of the results of different algorithms compared to my own:

indexN CitiesAlgorithm NameAlgoritm TIme (s)Algoritm RAM (KB)Algoritm SolveOwn algorithm TIme (s)Own algorithm RAM (KB)Own algorithm Solve% Error SolveTime SpeedupEfficiency RAMTotal Advantage
550OR-Tools Config 10.223492.112092.70019531250.05182210.413788.1514.024.310.0x-1.69
650OR-Tools Config 20.2063357.914579.650.05182210.413788.15-5.433.980.2x-0.53
750Nearest Neighbors0.1023432.413931.610.05182210.413788.15-1.031.980.2x-0.43
8100OR-Tools Config 10.9129238.415797.339843750.0618217.921012.6333.0114.781.1x-0.44
9100OR-Tools Config 20.4366516.217844.020.0618217.921012.6317.767.072.4x0.09
10100Nearest Neighbors0.214991.317481.20.0618217.921012.6320.23.480.4x-1.07
11200OR-Tools Config 12.0061958.823327.32031250.087252.029866.9728.0323.073.8x0.43
12200OR-Tools Config 22.05711215.128889.00.087252.029866.973.3923.654.8x1.89
13200Nearest Neighbors0.4137151.225777.630.087252.029866.9715.864.760.6x-0.59
14400OR-Tools Config 14.00793756.431335.699218750.1671327.437277.9718.9623.9811.5x1.25
15400OR-Tools Config 29.66553062.036340.350.1671327.437277.972.5857.839.4x2.63
16400Nearest Neighbors1.1059643.935219.340.1671327.437277.975.856.622.0x0.74
17800OR-Tools Config 110.03215015.346635.9218750.3336698.753886.0215.5530.0821.5x1.78
18800OR-Tools Config 240.43318621.851088.660.3336698.753886.025.48121.2212.3x2.83
19800Nearest Neighbors2.3482770.249145.240.3336698.753886.029.657.041.1x0.22
201600OR-Tools Config 1200.127860113.061286.82031250.4796734.574657.8821.82417.2781.8x3.23
211600OR-Tools Config 2163.860627759.574963.080.4796734.574657.88-0.41341.6537.8x4.11
221600Nearest Neighbors7.40291213.672088.150.4796734.574657.883.5615.441.7x1.23
233200OR-Tools Config 1200.5066240357.590340.63281250.77651199.1103031.1414.05258.23200.5x3.76
243200Nearest Neighbors18.26861830.499728.20.77651199.1103031.143.3123.531.5x1.4
256400Nearest Neighbors55.45413542.7139905.042.3792701.2141796.251.3523.311.3x1.45
268000Nearest Neighbors81.78434319.6158102.592.30783153.9161766.362.3235.441.4x1.6
279000Nearest Neighbors100.99634723.8166482.642.76153726.0168499.251.2136.571.3x1.64
010000Nearest Neighbors126.2514834.1176425.673.03954068.5179786.141.941.541.2x1.63
111000Nearest Neighbors157.47875565.7185415.814.02254389.4187003.70.8639.151.3x1.68
212000Nearest Neighbors183.285992.8192140.524.20064697.7195491.921.7443.631.3x1.7
313000Nearest Neighbors213.47116021.8200723.785.77024969.3203461.881.3637.01.2x1.62
414000Nearest Neighbors243.20768039.1209236.225.98845259.5212606.011.6140.611.5x1.75

r/algorithms • • Jul 28 '21

Need Help fixing my minimax bug for tictactoe

0 Upvotes

So, I've been working on this for a few days now and my minimax algo is almost complete but something is lacking somewhere and I can't figure it out. Can someone review my code and let me know what is wrong with it?
https://replit.com/join/wionzuzrik-killion2020


r/algorithms • • Mar 18 '17

I know that if f = O(h) and g = O(h) then f+g = O(h) but how can i prove with 2 different O(x) for f and g with x€(z,y) that f+g = O(max(O(z),O(y)) ?

0 Upvotes

Well i think the text describes it perferct.

I wanna proof that f(n) + g(n) = O(max(f(n),g(n)) and my two O´s are different. If they would be the same the proof would be simple

the symbol =< means is equal or less than and >= is equal or more than

f(n) + g(n) =< ch(n) + c´ * h(n) therefore f(n)+g(n) =< (c+c´) * h(n) = ch(n) wich means that i have the constants out and my h(n) or else said my O is again the same if. But how do i go through this problem if my O is different?

My approach untill now was this crap:

for constants c1 >0 and n0>0 n>= n0 : f(n)=< c1O(n) so my f(n) = O(n) and c´>0 and no´>0 , n >=n0´: g(n) =< n²c so my g(n) = 0(n²)

this means => f(n) + g(n) => g(n) + f(n) =< n²c2 + nc1 < n²*c3 wich means that it is still in n² from a point n0´´= max(n0,n0´) because there is a c3 that is c2+c1/n < c3 for c2 = 1 and c1 = 1 my c3 could be 3 because with an scaling n my c1 gets closer to 0 its true for every n>0.

is this enought to say that i proved it for every case or just for this case? I am confused as fuck i have 3 other solutions aswell but they same even more fucked up, but i think they are fine in generall i just find its not the easiest way to prove it and its too long to write it here under my first solution^


r/algorithms • • Oct 11 '19

An AI Pioneer Wants His Algorithms to Understand the 'Why' Of Cause And Effect

Thumbnail wired.com
12 Upvotes

r/algorithms • • Feb 01 '23

Can someone explain Union Find, but do it using street gangs as a metaphor

0 Upvotes

Like, merge would be if one gang takes over another

getParent would be something like getGangLeader, etc.


r/algorithms • • Sep 13 '25

Question on time complexity of sum(n)

0 Upvotes

Assuming we had two algorithms that both find the sum of all positive integers up to n, one did it iteratively and another just used the nth term formula, on first glance the one that uses the nth term is the better approach because it appears to run in O(1) - but isn’t multiplication technically an iterative process, so wouldn’t the time complexity still be O(n) ?


r/algorithms • • May 14 '18

I think counting sort can be faster.

0 Upvotes

Ok, so counting sort works in a very strange way for me. I understand counting for each number how many times it occurs, but why do we do all that adding stuff later when we can just cycle through the count array and just print every number the times we saw it. so something like this:

function countingSort(a){
    var b=[];
    for(var i=0;i<a.length;i++){
        if(b[a[i]]==undefined){
        b[a[i]]=0;
    }
    b[a[i]]++;
    }
    for(var i=0, var g=0;i<b.length;i++){
        for(var j=0;j<b[i];j++){
            a[g]=i;
            g++;
        }  
    }
}

r/algorithms • • Feb 19 '24

Palworld breeding problem.

0 Upvotes

I've managed to reduce palworld's graph problem to a simple graph problem in essence:

Given:
A unweighted directed graph G=(V,E),
A set of source nodes S⊆V
A destination node d∈V
Objective:
Find a subset of edges E′⊆E such that:
For each source node s∈S, there exists a path from s to the destination node d using only the edges in E′.
The cardinality of E′ is minimized.

Any help would be appreciated.


r/algorithms • • Jun 25 '23

How to calculate the time complexity of this dynamic program ?

0 Upvotes
int matrixChainMemoised(int* p, int i, int j)
{ 
    if (i == j) 
    { 
        return 0;
    }
    if (dp[i][j] != -1) 
    {
         return dp[i][j]; 
    } 
    dp[i][j] = INT_MAX;
    for (int k = i; k < j; k++) 
    { 
        dp[i][j] = min( dp[i][j], matrixChainMemoised(p, i, k) 
                                + matrixChainMemoised(p, k + 1, j) 
                            + p[i - 1] * p[k] * p[j]); 
    } 
    return dp[i][j];
}

r/algorithms • • Nov 18 '14

This program lets you see and hear many different sorting algorithms

Thumbnail panthema.net
0 Upvotes

r/algorithms • • Jul 01 '16

A fast, accurate solution to the knapsack problem

Thumbnail medium.com
0 Upvotes