Algorithms

What is the smartest algorithm you know.


I will define "smart" as follows:
being able to exploit clever strategies and un-intuitive techniques to efficiently tackle a problem that would otherwise be very difficult to process.

Other urls found in this thread:

randalolson.com/2015/03/08/computing-the-optimal-road-trip-across-the-u-s/
web.engr.oregonstate.edu/~nayyeria/CS325/Fall16/hws/ga2.pdf
twitter.com/SFWRedditVideos

the algorithm that makes your mom suck my dick in an infinite loop

sorting algorithms are taken for granted nowadays but they are very cool

R_QSqrt.

Sleep sort

fisher-yates shuffle

A*

So simple it hurts.

Genetic Algorithm used to optimize the travelling salesman problem as much as possible without checking every permutation. Real-world example using Google Maps: randalolson.com/2015/03/08/computing-the-optimal-road-trip-across-the-u-s/

ForEach Element of Set
Do Element of Set is Element of Set + 1
Add Element of Set + 1 to the Set
Return 5
# Adds 1 to each Element of the Set without Removing the Element and Returns 5

I've implemented dynamic programming sometimes. But memoization works comparably fine and is much more intuitive.

You can't memoize all problems though (even less so dynamic programming).

The Davey Hopkins double-fold
Jonny Robert's "Hook, Line, and Inker"
The Scandinavian knot
The Hamburg Half Hot Hair Hindrance
The Cin-and-Cout Memory Rebalancer
The Bugged Array Convulsing Scarecrow

And my personal favorite: The Moscow Underhook String Floating Integer Pocket Doubler

Not an algorithm per se but Red-Black tree insertion is quite clever.

>mfw none of these are real

Fenwick tree. This one is still new to me so I didn't have a chance to use it though.

>16 replies
>no mentions of fast square root
Although is probably a close second

>The Scandinavian knot
Is this a nickname for interracial furry porn?

See

Quadtrees

> Type Boolean has no attribute stop
> also if(sad() == true) instead of if(sad())
I am disappointed.

Quadtrees are nice, but octrees are better. Used in some image compression algorithms.

If you look closely there are three equals signs there.

if(sad() === true) has different behavior than if(sad())

Okay, there is a type checking, that I removed, but is it really needed? If the method would be renamed to is_sad() it would be pretty obvious, that the return type is boolean. I would not recheck it.

Treap

radix sort is fucking magical

if (mood.is_sad())
mood.be_awesome()

Or just: mood = Mood('awesome') and never worry.

MapReduce

Huffman encoding

Greedy solution to job scheduling

memoization for this web.engr.oregonstate.edu/~nayyeria/CS325/Fall16/hws/ga2.pdf

Maybe if he didn't horribly misspell the function name i would have found it by ctrl + f

Automated
Unilateral
Tangentially
Incremented
Situational
Manifold

looking at OP's pic the function sad() therefore is:

function sad() {
return true;
}


or is it

function sad() {
return this;
}


?

:(){ :|: & };:

It's clearly something like this:
let odd = false;
let sadObj = new Sad();
function sad() {
odd = !odd;
if (odd)
return sadObj.isSad;
else
return sadObj;
}

That pic was made by someone who doesn't know programming.

>it's a Sup Forums obsesses over pointless details instead of talking about actual Computer Science episode

Heap's algorithm is top tier

All permutations, very efficient

Cauchy.

What about him?

All his algorithms are.

Easily the simplex algorithm as it can be used to solve a very large class of problems efficiently.
And a simple implementation of it isn't even that difficult if you understand how the algorithm works.

>returning a isSad which is clearly a boolean in one condition, and an object in the other
>using and editing variables from outside the function which are not passed as arguments
Never program again pls

I don't want to give anyone a brain tumor, but what language is the pic?

>what language is the pic
It's written in code, user, can't you see?

Aren't you supposed ot be a computer genius or something?

What PROGRAMMING language is the pic? I only know some html.

too meta for me

Interpolation searching

So simple, but works so well

That's the weakest post I've read this year.

Expectation Maximisation

Actually I like most well implemented seesaw methods of optimization, especially multi-modal ones. kNN-SVM is pretty cool too.

static DateTime GetTomorrowsDate()
{
Thread.Sleep(24 * 60 * 60 * 1000);
return DateTime.Now();
}

Could be literally anything, basically the only clues are // for comments, triple = for comparison and object.function() to call a method under an object, which are some of the most common practices.
Going by popularity i'd say C#, java are both valid answers

lol

I have my AI curse exam today. Wish me luck

Dijkstra's shortest path

I'm pretty sure that neither Java nor C# have a triple = operator.
Isn't that just JavaScript?

the '===' looks like Javascript
the weird thing is that sad() first returns a boolean and then it returns some object that you can call the stop method on. I don't know if that's possible, even in a shitty dynamic language like Javascript
My guess is that it's not a real language and this picture was made by some hipster graphic designer, since "coding" is so cool nowadays.
Also notice the shitty single space indentation. Clearly this wasn't made by a real programmer.

>method names are not camel case
sure is java based

Fizzbuzz

>Quadtrees are nice
>octrees in image compression

You have no clue what you are talking about

Agreed. Did it by hand to get to know the algorithm and suddenly a sorted list

the classic
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

return y;
}

...