Top 10 most interesting algorithms ever created in computer science. Learn how software engineers have innovative techniques to solve real world problems. 

#science #programming #top10 

💬 Chat with Me on Discord

https://discord.gg/fireship

🔗 Resources

Wave Function Collapse demo https://jaxry.github.io/wave-function-collapse/
Cryptography concepts https://youtu.be/NuyzuNBFWxQ
10 Sorting Algorithms Explained https://youtu.be/RfXt_qHDEPw

🔥 Get More Content - Upgrade to PRO

Upgrade at https://fireship.io/pro
Use code YT25 for 25% off PRO access 

🎨 My Editor Settings

- Atom One Dark 
- vscode-icons
- Fira Code Font

🔖 Topics Covered

- Algorithms every programmer should know
- How does wave function collapse work
- Quantum computer algorithms
- How do distributed systems stay secure?
- Sorting algorithms explained
2024-02-04T04:58:00.827Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
e4b8763c-5a49-4ee7-9aea-84467e9686de
d1a5cc393f52827e2f7738b48b56729885db75d3bb4c3f32b820447727a98d69
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field?
Yeah.
I didn't think so.
But back in 87, 2 programmers at General Electric did.
They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans.
Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk.
Most algorithms belong in a dumpster, but some are fast, skin.
Some are beautiful and some are so weird, they're indistinguishable from magic.
Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world.
1st on the list, we have wave function collapse.
One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle.
It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build.
It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically.
Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity?
We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly.
What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities.
It's the wave function.
Then upon observation, it collapses into a particle.
Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI.
Speaking of which, AI is weird as hell.
Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion.
But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration.
In artificial intelligence, the process is reversed.
The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy.
But first, you'll need to train model that can do this well.
The diffusion algorithm works in 2 phases.
In the forward phase, it gradually adds noise to an image step by step until it becomes completely random.
In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image.
When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models.
It's highly compute intensive, but also works well on audio.
And the next frontier is diffusion for video generation.
But now Now let's talk about simulated annealing.
One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions.
Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others.
Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects.
The same idea is used in optimization algorithms to find the best answer or n a c of good answers.
Imagine trying to find the highest point in a mountain range full of peaks and valleys.
A simple hill climb algorithm won't work because there are many local peaks.
Initially, the temperature sky allowing the algorithm to explore freely.
As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution.
The off here is exploration versus exploitation.
But the reason I included this algorithm is because it's also a good way for beginners to learn how to code.
Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in.
But we can't talk about algorithms without talking about sorting.
And the most ingenious sorting algorithm of all time is without a doubt, sleep sort.
The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently.
However, some random genius on 4 chan found a better way, but it's a bit unconventional.
Here's what the code looks like in bash.
It's incredibly simple.
It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element.
Then finally, after waking up, it prints that element.
It's genius because it delegates the sorting to the CPU scheduler.
It's also dumb and useless because it delegates sorting to the CPU scheduler.
Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again.
It's like playing the lottery.
But what if we apply the same algorithm with quantum mechanics to the multiverse?
If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes.
That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted.
The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier.
Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it.
That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem.
It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature.
But it's based on one simple mathematical reality.
Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force.
Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm.
Prime factoring is pretty simple, but how this algorithm does it is where things get weird.
It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel.
The algorithm is legit, but so far, the biggest number ever factored is 21.
Even IBM's state of the art Q System 1 fails when trying to factor the number 35.
However, just recently, skin.
The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm.
Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world.
At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look.
So first, we start with a 3 d scalar field, which might represent data from an MRI machine.
Each point in the 3 d space is represented by a single number or a scalar.
The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer.
This results in 256 different possibilities, which point to a precalculated array of polygons.
The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software.
And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d.
In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem.
Imagine you're a general in the Byzantine army.
You're camped around a city with a few other generals with plans to attack it the next morning.
But what if one of the generals skitrunk and wakes up too hungover to attack.
The entire system could collapse.
Computers have the same problem.
Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen.
Luckily, algorithms like PBFT are designed to solve this.
They can keep a distributed network working properly even if up to 1 third of its nodes go haywire.
It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system.
The other nodes will respond back in agreement.
Then after a certain threshold, a consensus is formed.
Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent.
Algorithms like this are essential for blockchain technology and things like distributed cloud databases.
What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program.
It was created back in 86 and simulates the flocking behavior of birds.
What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules.
In this case, the birdoids have three rules.
They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates.
The end result are these intricate patterns that weren't programmed directly, but just emerge naturally.
But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search.
It's weird because it becomes faster and more efficient as the string it's searching becomes bigger.
That seems impossible, but it makes sense when you understand the algorithm.
It scans skin's text from right to left, then has two rules.
When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table.
Scale.
Likewise, if it finds a partial match, then a mismatch occurs.
It has a separate pre calculated table that maximizes the number of characters it can safely skip.
These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character.
In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters.
And if you've ever wondered why GREP is so fast, you have this algorithm to thank.

Speaker 0: Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field? Yeah. I didn't think so. But back in 87, 2 programmers at General Electric did. They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans.

Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk. Most algorithms belong in a dumpster, but some are fast, skin. Some are beautiful and some are so weird, they're indistinguishable from magic. Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world. 1st on the list, we have wave function collapse.

One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle. It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build. It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically. Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity? We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly.

What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities. It's the wave function. Then upon observation, it collapses into a particle. Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI. Speaking of which, AI is weird as hell.

Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion. But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration. In artificial intelligence, the process is reversed. The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy. But first, you'll need to train model that can do this well.

The diffusion algorithm works in 2 phases. In the forward phase, it gradually adds noise to an image step by step until it becomes completely random. In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image. When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models. It's highly compute intensive, but also works well on audio.

And the next frontier is diffusion for video generation. But now Now let's talk about simulated annealing. One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions. Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others. Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects.

The same idea is used in optimization algorithms to find the best answer or n a c of good answers. Imagine trying to find the highest point in a mountain range full of peaks and valleys. A simple hill climb algorithm won't work because there are many local peaks. Initially, the temperature sky allowing the algorithm to explore freely. As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution.

The off here is exploration versus exploitation. But the reason I included this algorithm is because it's also a good way for beginners to learn how to code. Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in. But we can't talk about algorithms without talking about sorting. And the most ingenious sorting algorithm of all time is without a doubt, sleep sort.

The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently. However, some random genius on 4 chan found a better way, but it's a bit unconventional. Here's what the code looks like in bash. It's incredibly simple. It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element.

Then finally, after waking up, it prints that element. It's genius because it delegates the sorting to the CPU scheduler. It's also dumb and useless because it delegates sorting to the CPU scheduler. Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again. It's like playing the lottery.

But what if we apply the same algorithm with quantum mechanics to the multiverse? If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes. That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted. The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier. Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it.

That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem. It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature. But it's based on one simple mathematical reality. Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force. Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm.

Prime factoring is pretty simple, but how this algorithm does it is where things get weird. It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel. The algorithm is legit, but so far, the biggest number ever factored is 21. Even IBM's state of the art Q System 1 fails when trying to factor the number 35. However, just recently, skin.

The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm. Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world. At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look. So first, we start with a 3 d scalar field, which might represent data from an MRI machine. Each point in the 3 d space is represented by a single number or a scalar.

The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer. This results in 256 different possibilities, which point to a precalculated array of polygons. The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software. And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d. In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem.

Imagine you're a general in the Byzantine army. You're camped around a city with a few other generals with plans to attack it the next morning. But what if one of the generals skitrunk and wakes up too hungover to attack. The entire system could collapse. Computers have the same problem.

Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen. Luckily, algorithms like PBFT are designed to solve this. They can keep a distributed network working properly even if up to 1 third of its nodes go haywire. It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system. The other nodes will respond back in agreement.

Then after a certain threshold, a consensus is formed. Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent. Algorithms like this are essential for blockchain technology and things like distributed cloud databases. What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program. It was created back in 86 and simulates the flocking behavior of birds.

What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules. In this case, the birdoids have three rules. They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates. The end result are these intricate patterns that weren't programmed directly, but just emerge naturally. But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search.

It's weird because it becomes faster and more efficient as the string it's searching becomes bigger. That seems impossible, but it makes sense when you understand the algorithm. It scans skin's text from right to left, then has two rules. When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table. Scale.

Likewise, if it finds a partial match, then a mismatch occurs. It has a separate pre calculated table that maximizes the number of characters it can safely skip. These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character. In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters. And if you've ever wondered why GREP is so fast, you have this algorithm to thank.
Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field? Yeah. I didn't think so. But back in 87, 2 programmers at General Electric did. They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans. Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk. Most algorithms belong in a dumpster, but some are fast, skin. Some are beautiful and some are so weird, they're indistinguishable from magic. Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world. 1st on the list, we have wave function collapse. One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle. It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build. It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically. Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity?
physics
artificial intelligence
science
robotics
cosmology
geometry
mathematics
particle physics
logic
machine learning
neural networks
We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly. What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities. It's the wave function. Then upon observation, it collapses into a particle. Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI. Speaking of which, AI is weird as hell. Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion. But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration. In artificial intelligence, the process is reversed. The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy. But first, you'll need to train model that can do this well. The diffusion algorithm works in 2 phases. In the forward phase, it gradually adds noise to an image step by step until it becomes completely random. In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image. When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models. It's highly compute intensive, but also works well on audio. And the next frontier is diffusion for video generation. But now Now let's talk about simulated annealing. One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions. Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others. Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects.
thermodynamics
particle physics
logic
computer science
artificial intelligence
robotics
modeling
inflation
machine learning
technology
programming
neural networks
geometry
The same idea is used in optimization algorithms to find the best answer or n a c of good answers. Imagine trying to find the highest point in a mountain range full of peaks and valleys. A simple hill climb algorithm won't work because there are many local peaks.
Initially, the temperature sky allowing the algorithm to explore freely. As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution. The off here is exploration versus exploitation. But the reason I included this algorithm is because it's also a good way for beginners to learn how to code. Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in.
programming
weather
mining
artificial intelligence
climate science
But we can't talk about algorithms without talking about sorting. And the most ingenious sorting algorithm of all time is without a doubt, sleep sort. The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently. However, some random genius on 4 chan found a better way, but it's a bit unconventional. Here's what the code looks like in bash. It's incredibly simple. It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element. Then finally, after waking up, it prints that element. It's genius because it delegates the sorting to the CPU scheduler. It's also dumb and useless because it delegates sorting to the CPU scheduler. Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again.
It's like playing the lottery. But what if we apply the same algorithm with quantum mechanics to the multiverse? If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes. That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted.
cosmology
The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier.
Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it. That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem. It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature. But it's based on one simple mathematical reality.
security
cryptocurrency
Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force.
Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm. Prime factoring is pretty simple, but how this algorithm does it is where things get weird. It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel. The algorithm is legit, but so far, the biggest number ever factored is 21. Even IBM's state of the art Q System 1 fails when trying to factor the number 35.
artificial intelligence
machine learning
However, just recently, skin. The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm. Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world.
At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look. So first, we start with a 3 d scalar field, which might represent data from an MRI machine. Each point in the 3 d space is represented by a single number or a scalar. The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer. This results in 256 different possibilities, which point to a precalculated array of polygons. The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software. And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d. In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem. Imagine you're a general in the Byzantine army. You're camped around a city with a few other generals with plans to attack it the next morning. But what if one of the generals skitrunk and wakes up too hungover to attack. The entire system could collapse. Computers have the same problem.
geometry
mathematics
neural networks
military
visualization
astrology
Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen. Luckily, algorithms like PBFT are designed to solve this. They can keep a distributed network working properly even if up to 1 third of its nodes go haywire. It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system. The other nodes will respond back in agreement.
networking
telecommunications
radio
systems
Then after a certain threshold, a consensus is formed. Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent.
Algorithms like this are essential for blockchain technology and things like distributed cloud databases. What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program. It was created back in 86 and simulates the flocking behavior of birds. What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules. In this case, the birdoids have three rules. They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates. The end result are these intricate patterns that weren't programmed directly, but just emerge naturally. But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search. It's weird because it becomes faster and more efficient as the string it's searching becomes bigger.
birds
artificial intelligence
neural networks
insects
machine learning
wildlife
That seems impossible, but it makes sense when you understand the algorithm. It scans skin's text from right to left, then has two rules. When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table. Scale. Likewise, if it finds a partial match, then a mismatch occurs. It has a separate pre calculated table that maximizes the number of characters it can safely skip. These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character. In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters. And if you've ever wondered why GREP is so fast, you have this algorithm to thank.
Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field? Yeah. I didn't think so. But back in 87, 2 programmers at General Electric did. They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans. Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk. Most algorithms belong in a dumpster, but some are fast, skin. Some are beautiful and some are so weird, they're indistinguishable from magic. Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world. 1st on the list, we have wave function collapse. One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle. It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build. It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically. Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity? We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly. What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities. It's the wave function. Then upon observation, it collapses into a particle. Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI. Speaking of which, AI is weird as hell. Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion. But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration. In artificial intelligence, the process is reversed. The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy. But first, you'll need to train model that can do this well. The diffusion algorithm works in 2 phases. In the forward phase, it gradually adds noise to an image step by step until it becomes completely random. In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image. When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models. It's highly compute intensive, but also works well on audio. And the next frontier is diffusion for video generation. But now Now let's talk about simulated annealing. One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions. Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others. Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects. The same idea is used in optimization algorithms to find the best answer or n a c of good answers. Imagine trying to find the highest point in a mountain range full of peaks and valleys. A simple hill climb algorithm won't work because there are many local peaks. Initially, the temperature sky allowing the algorithm to explore freely. As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution. The off here is exploration versus exploitation. But the reason I included this algorithm is because it's also a good way for beginners to learn how to code. Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in. But we can't talk about algorithms without talking about sorting. And the most ingenious sorting algorithm of all time is without a doubt, sleep sort. The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently. However, some random genius on 4 chan found a better way, but it's a bit unconventional. Here's what the code looks like in bash. It's incredibly simple. It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element. Then finally, after waking up, it prints that element. It's genius because it delegates the sorting to the CPU scheduler. It's also dumb and useless because it delegates sorting to the CPU scheduler. Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again. It's like playing the lottery. But what if we apply the same algorithm with quantum mechanics to the multiverse? If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes. That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted. The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier. Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it. That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem. It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature. But it's based on one simple mathematical reality. Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force. Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm. Prime factoring is pretty simple, but how this algorithm does it is where things get weird. It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel. The algorithm is legit, but so far, the biggest number ever factored is 21. Even IBM's state of the art Q System 1 fails when trying to factor the number 35. However, just recently, skin. The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm. Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world. At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look. So first, we start with a 3 d scalar field, which might represent data from an MRI machine. Each point in the 3 d space is represented by a single number or a scalar. The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer. This results in 256 different possibilities, which point to a precalculated array of polygons. The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software. And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d. In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem. Imagine you're a general in the Byzantine army. You're camped around a city with a few other generals with plans to attack it the next morning. But what if one of the generals skitrunk and wakes up too hungover to attack. The entire system could collapse. Computers have the same problem. Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen. Luckily, algorithms like PBFT are designed to solve this. They can keep a distributed network working properly even if up to 1 third of its nodes go haywire. It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system. The other nodes will respond back in agreement. Then after a certain threshold, a consensus is formed. Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent. Algorithms like this are essential for blockchain technology and things like distributed cloud databases. What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program. It was created back in 86 and simulates the flocking behavior of birds. What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules. In this case, the birdoids have three rules. They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates. The end result are these intricate patterns that weren't programmed directly, but just emerge naturally. But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search. It's weird because it becomes faster and more efficient as the string it's searching becomes bigger. That seems impossible, but it makes sense when you understand the algorithm. It scans skin's text from right to left, then has two rules. When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table. Scale. Likewise, if it finds a partial match, then a mismatch occurs. It has a separate pre calculated table that maximizes the number of characters it can safely skip. These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character. In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters. And if you've ever wondered why GREP is so fast, you have this algorithm to thank.
Have
have
you
you
ever
ever
woken
woken
up
up
in
in
the
the
middle
middle
of
of
the
the
night
night
in
in
a
a
panic
panic
wondering
wondering
how
how
to
to
extract
extract
a
a
polygonal
polygonal
mesh
mesh
of
of
an
an
isosurface
isosurface
from
from
a
a
3
3
dimensional
dimensional
discrete
discrete
scalar
scalar
field?
field
Yeah.
yeah
I
i
didn't
didn't
think
think
so.
so
But
but
back
back
in
in
87,
87
2
2
programmers
programmers
at
at
General
general
Electric
electric
did.
did
They
they
created
created
and
and
patented
patented
the
the
marching
marching
cubes
cubes
algorithm,
algorithm
an
an
algorithm
algorithm
that
that
has
has
likely
likely
saved
saved
countless
countless
lives
lives
by
by
allowing
allowing
doctors
doctors
to
to
visualize
visualize
data
data
from
from
CT
ct
and
and
MRI
mri
scans.
scans
Whenever
whenever
you
you
instruct
instruct
a
a
machine
machine
to
to
solve
solve
a
a
problem
problem
with
with
code,
code
you're
you're
creating
creating
an
an
algorithm,
algorithm
a
a
procedure
procedure
for
for
rearranging
rearranging
ones
ones
and
and
zeros
zeros
that
that
can
can
make
make
animals
animals
talk
talk
and
and
vacuums
vacuums
walk.
walk
Most
most
algorithms
algorithms
belong
belong
in
in
a
a
dumpster,
dumpster
but
but
some
some
are
are
fast,
fast
skin.
skin
Some
some
are
are
beautiful
beautiful
and
and
some
some
are
are
so
so
weird,
weird
they're
they're
indistinguishable
indistinguishable
from
from
magic.
magic
Today,
today
we'll
we'll
look
look
at
at
10
10
of
of
the
the
most
most
interesting
interesting
algorithms
algorithms
ever
ever
engineered
engineered
sphere,
sphere
and
and
how
how
they're
they're
used
used
to
to
solve
solve
very
very
interesting
interesting
problems
problems
in
in
the
the
real
real
world.
world
1st
1st
on
on
the
the
list,
list
we
we
have
have
wave
wave
function
function
collapse.
collapse
One
one
of
of
the
the
weirdest
weirdest
things
things
in
in
all
all
of
of
science
science
is
is
the
the
double
double
slit
slit
experiment,
experiment
where
where
particles
particles
behave
behave
like
like
a
a
wave
wave
when
when
you're
you're
not
not
looking,
looking
but
but
when
when
you
you
look,
look
they
they
suddenly
suddenly
collapse
collapse
down
down
to
to
a
a
particle.
particle
It
it
seems
seems
counterintuitive,
counterintuitive
but
but
it
it
makes
makes
total
total
sense
sense
when
when
you
you
realize
realize
we're
we're
living
living
in
in
a
a
simulation
simulation
and
and
the
the
universe
universe
wrote
wrote
algorithm
algorithm
to
to
cut
cut
down
down
on
on
its
its
AWS
aws
build.
build
It's
it's
an
an
interesting
interesting
concept
concept
to
to
think
think
about
about
philosophically,
philosophically
but
but
the
the
general
general
idea
idea
behind
behind
wave
wave
function
function
collapse
collapse
can
can
also
also
be
be
implemented
implemented
programmatically.
programmatically
Imagine
imagine
we
we
have
have
a
a
map
map
for
for
a
a
video
video
game,
game
but
but
what
what
if
if
this
this
is
is
a
a
side
side
scrolling
scrolling
game
game
that
that
can
can
go
go
on
on
for
for
eternity?
eternity
We
we
can't
can't
just
just
make
make
a
a
bigger
bigger
map,
map
we
we
need
need
an
an
algorithm
algorithm
to
to
procedurally
procedurally
generate
generate
it
it
on
on
the
the
fly.
fly
What's
what's
so
so
weird
weird
is
is
that
that
we
we
can
can
take
take
this
this
initial
initial
map
map
and
and
think
think
of
of
it
it
as
as
being
being
in
in
the
the
initial
initial
superposition
superposition
of
of
all
all
possibilities.
possibilities
It's
it's
the
the
wave
wave
function.
function
Then
then
upon
upon
observation,
observation
it
it
collapses
collapses
into
into
a
a
particle.
particle
Or
or
in
in
other
other
words,
words
it
it
selects
selects
a
a
random
random
map
map
tile
tile
but
but
follows
follows
a
a
consistent
consistent
set
set
of
of
rules,
rules
like
like
in
in
this
this
case,
case
making
making
sure
sure
that
that
the
the
roads
roads
are
are
always
always
connected,
connected
providing
providing
a
a
random
random
yet
yet
cohesive
cohesive
result
result
and
and
doesn't
doesn't
rely
rely
on
on
any
any
sort
sort
of
of
modern
modern
generative
generative
AI.
ai
Speaking
speaking
of
of
which,
which
AI
ai
is
is
weird
weird
as
as
hell.
hell
Diffusion
diffusion
is
is
a
a
machine
machine
learning
learning
algorithm
algorithm
originally
originally
developed
developed
at
at
OpenAI
openai
and
and
is
is
the
the
magic
magic
behind
behind
image
image
generators
generators
like
like
DALL
dall
E
e
and
and
Stable
stable
Diffusion.
diffusion
But
but
the
the
concept
concept
of
of
diffusion
diffusion
actually
actually
comes
comes
from
from
thermodynamics,
thermodynamics
where
where
particles
particles
spread
spread
from
from
areas
areas
of
of
higher
higher
concentration
concentration
to
to
lower
lower
concentration.
concentration
In
in
artificial
artificial
intelligence,
intelligence
the
the
process
process
is
is
reversed.
reversed
The
the
algorithm
algorithm
starts
starts
by
by
generating
generating
random
random
noise,
noise
which
which
would
would
be
be
like
like
high
high
entropy
entropy
and
and
thermodynamics,
thermodynamics
and
and
gradually
gradually
refines
refines
it
it
to
to
a
a
structured
structured
image,
image
which
which
would
would
be
be
lower
lower
entropy.
entropy
But
but
first,
first
you'll
you'll
need
need
to
to
train
train
model
model
that
that
can
can
do
do
this
this
well.
well
The
the
diffusion
diffusion
algorithm
algorithm
works
works
in
in
2
2
phases.
phases
In
in
the
the
forward
forward
phase,
phase
it
it
gradually
gradually
adds
adds
noise
noise
to
to
an
an
image
image
step
step
by
by
step
step
until
until
it
it
becomes
becomes
completely
completely
random.
random
In
in
the
the
second
second
phase,
phase
the
the
algorithm
algorithm
reverses
reverses
this
this
process,
process
reconstructing
reconstructing
it
it
back
back
into
into
a
a
coherent
coherent
image.
image
When
when
the
the
algorithm
algorithm
runs
runs
over
over
millions
millions
of
of
labeled
labeled
images,
images
we
we
get
get
a
a
collection
collection
of
of
weights
weights
that
that
can
can
be
be
used
used
to
to
generate
generate
new
new
images
images
out
out
of
of
thin
thin
air,
air
allowing
allowing
us
us
to
to
build
build
an
an
infinite
infinite
army
army
OnlyFans
onlyfans
models.
models
It's
it's
highly
highly
compute
compute
intensive,
intensive
but
but
also
also
works
works
well
well
on
on
audio.
audio
And
and
the
the
next
next
frontier
frontier
is
is
diffusion
diffusion
for
for
video
video
generation.
generation
But
but
now
now
Now
now
let's
let's
talk
talk
about
about
simulated
simulated
annealing.
annealing
One
one
frustrating
frustrating
thing
thing
about
about
programming
programming
is
is
that
that
for
for
many
many
problems,
problems
there's
there's
not
not
just
just
one
one
solution,
solution
but
but
many
many
solutions.
solutions
Like
like
an
an
Amazon
amazon
warehouse
warehouse
has
has
many
many
different
different
ways
ways
to
to
organize
organize
its
its
inventory,
inventory
but
but
some
some
ways
ways
are
are
more
more
efficient
efficient
than
than
others.
others
Annealing
annealing
is
is
a
a
word
word
that
that
comes
comes
from
from
metallurgy,
metallurgy
where
where
metals
metals
are
are
skid
skid
heated
heated
up
up
and
and
cooled
cooled
down
down
over
over
and
and
over
over
again
again
to
to
remove
remove
defects.
defects
The
the
same
same
idea
idea
is
is
used
used
in
in
optimization
optimization
algorithms
algorithms
to
to
find
find
the
the
best
best
answer
answer
or
or
n
n
a
a
c
c
of
of
good
good
answers.
answers
Imagine
imagine
trying
trying
to
to
find
find
the
the
highest
highest
point
point
in
in
a
a
mountain
mountain
range
range
full
full
of
of
peaks
peaks
and
and
valleys.
valleys
A
a
simple
simple
hill
hill
climb
climb
algorithm
algorithm
won't
won't
work
work
because
because
there
there
are
are
many
many
local
local
peaks.
peaks
Initially,
initially
the
the
temperature
temperature
sky
sky
allowing
allowing
the
the
algorithm
algorithm
to
to
explore
explore
freely.
freely
As
as
time
time
goes
goes
on
on
though,
though
the
the
temperature
temperature
is
is
lowered,
lowered
which
which
decreases
decreases
the
the
probability
probability
of
of
accepting
accepting
a
a
worse
worse
solution.
solution
The
the
off
off
here
here
is
is
exploration
exploration
versus
versus
exploitation.
exploitation
But
but
the
the
reason
reason
I
i
included
included
this
this
algorithm
algorithm
is
is
because
because
it's
it's
also
also
a
a
good
good
way
way
for
for
beginners
beginners
to
to
learn
learn
how
how
to
to
code.
code
Initially,
initially
you
you
start
start
out
out
exploring
exploring
all
all
kinds
kinds
of
of
different
different
technologies
technologies
and
and
frameworks,
frameworks
then
then
eventually
eventually
you
you
find
find
one
one
specific
specific
area
area
to
to
exploit
exploit
and
and
specialize
specialize
in.
in
But
but
we
we
can't
can't
talk
talk
about
about
algorithms
algorithms
without
without
talking
talking
about
about
sorting.
sorting
And
and
the
the
most
most
ingenious
ingenious
sorting
sorting
algorithm
algorithm
of
of
all
all
time
time
is
is
without
without
a
a
doubt,
doubt
sleep
sleep
sort.
sort
The
the
majority
majority
of
of
sane
sane
sorting
sorting
algorithms
algorithms
out
out
there
there
use
use
strategies
strategies
like
like
divide
divide
conquer
conquer
to
to
break
break
up
up
an
an
array
array
into
into
subarrays
subarrays
where
where
it
it
can
can
be
be
sorted
sorted
more
more
efficiently.
efficiently
However,
however
some
some
random
random
genius
genius
on
on
4
4
chan
chan
found
found
a
a
better
better
way,
way
but
but
it's
it's
a
a
bit
bit
unconventional.
unconventional
Here's
here's
what
what
the
the
code
code
looks
looks
like
like
in
in
bash.
bash
It's
it's
incredibly
incredibly
simple.
simple
It
it
loops
loops
over
over
the
the
array,
array
and
and
then
then
for
for
each
each
element,
element
it
it
opens
opens
up
up
a
a
new
new
thread
thread
that
that
sleeps
sleeps
for
for
the
the
amount
amount
of
of
time
time
proportional
proportional
to
to
the
the
value
value
of
of
its
its
element.
element
Then
then
finally,
finally
after
after
waking
waking
up,
up
it
it
prints
prints
that
that
element.
element
It's
it's
genius
genius
because
because
it
it
delegates
delegates
the
the
sorting
sorting
to
to
the
the
CPU
cpu
scheduler.
scheduler
It's
it's
also
also
dumb
dumb
and
and
useless
useless
because
because
it
it
delegates
delegates
sorting
sorting
to
to
the
the
CPU
cpu
scheduler.
scheduler
Speaking
speaking
of
of
which,
which
you
you
might
might
be
be
familiar
familiar
with
with
another
another
useless
useless
sorting
sorting
algorithm,
algorithm
BOGO
bogo
sort,
sort
which
which
tries
tries
to
to
sort
sort
an
an
array
array
by
by
randomly
randomly
guessing
guessing
over
over
and
and
over
over
again.
again
It's
it's
like
like
playing
playing
the
the
lottery.
lottery
But
but
what
what
if
if
we
we
apply
apply
the
the
same
same
algorithm
algorithm
with
with
quantum
quantum
mechanics
mechanics
to
to
the
the
multiverse?
multiverse
If
if
we're
we're
to
to
trust
trust
multiverse
multiverse
science,
science
we
we
know
know
that
that
all
all
possible
possible
outcomes
outcomes
exist
exist
in
in
separate
separate
parallel
parallel
universes.
universes
That
that
means
means
as
as
a
a
developer,
developer
if
if
you
you
find
find
yourself
yourself
with
with
an
an
unsorted
unsorted
array,
array
there's
there's
or
or
some
some
other
other
parallel
parallel
universe
universe
where
where
it
it
is
is
sorted.
sorted
The
the
technology
technology
isn't
isn't
quite
quite
there
there
yet,
yet
but
but
if
if
we
we
could
could
randomly
randomly
observe
observe
these
these
other
other
universes
universes
to
to
find
find
the
the
sorted
sorted
array,
array
we
we
could
could
then
then
use
use
a
a
portal
portal
gun
gun
to
to
travel
travel
to
to
that
that
universe,
universe
which
which
would
would
make
make
our
our
lives
lives
much
much
easier.
easier
Although,
although
we
we
would
would
obviously
obviously
have
have
to
to
kill
kill
the
the
version
version
of
of
ourself
ourself
in
in
that
that
universe,
universe
but
but
if
if
it's
it's
a
a
large
large
array,
array
quantum
quantum
Bogosort
bogosort
might
might
be
be
worth
worth
it.
it
That's
that's
purely
purely
hypothetical,
hypothetical
but
but
one
one
of
of
the
the
most
most
practical
practical
and
and
goaded
goaded
algorithms
algorithms
of
of
all
all
time
time
is
is
SCAR
scar
SA,
sa
a
a
public
public
key
key
cryptosystem.
cryptosystem
It's
it's
essential
essential
for
for
digital
digital
security,
security
allowing
allowing
people
people
on
on
the
the
Internet
internet
to
to
lock
lock
their
their
mailboxes
mailboxes
and
and
sign
sign
their
their
letters
letters
with
with
a
a
unique
unique
signature.
signature
But
but
it's
it's
based
based
on
on
one
one
simple
simple
mathematical
mathematical
reality.
reality
Multiplying
multiplying
large
large
numbers
numbers
to
to
find
find
2
2
original
original
large
large
prime
prime
numbers
numbers
is
is
extremely
extremely
difficult
difficult
and
and
time
time
like
like
it
it
take
take
your
your
laptop
laptop
300,000,000,000,000
300,000,000,000,000
years
years
to
to
brute
brute
force.
force
Unless
unless
quantum
quantum
computers
computers
become
become
a
a
thing,
thing
and
and
we
we
can
can
start
start
leveraging
leveraging
Shor's
shor's
algorithm,
algorithm
which
which
can
can
solve
solve
the
the
integer
integer
factorization
factorization
problem
problem
exponentially
exponentially
faster
faster
than
than
any
any
classical
classical
algorithm.
algorithm
Prime
prime
factoring
factoring
is
is
pretty
pretty
simple,
simple
but
but
how
how
this
this
algorithm
algorithm
does
does
it
it
is
is
where
where
things
things
get
get
weird.
weird
It
it
relies
relies
on
on
concepts
concepts
like
like
cubits,
cubits
skits
skits
superposition
superposition
and
and
entanglement
entanglement
to
to
perform
perform
massive
massive
amounts
amounts
of
of
calculations
calculations
in
in
parallel.
parallel
The
the
algorithm
algorithm
is
is
legit,
legit
but
but
so
so
far,
far
the
the
biggest
biggest
number
number
ever
ever
factored
factored
is
is
21.
21
Even
even
IBM's
ibm's
state
state
of
of
the
the
art
art
Q
q
System
system
1
1
fails
fails
when
when
trying
trying
to
to
factor
factor
the
the
number
number
35.
35
However,
however
just
just
recently,
recently
skin.
skin
The
the
Chinese
chinese
factored
factored
this
this
big
big
ass
ass
number
number
with
with
a
a
quantum
quantum
computer,
computer
but
but
it
it
uses
uses
a
a
different
different
algorithm
algorithm
that
that
doesn't
doesn't
scale
scale
very
very
well
well
for
for
large
large
numbers
numbers
unlike
unlike
Shor's
shor's
algorithm.
algorithm
Everything
everything
is
is
safe
safe
for
for
now,
now
but
but
when
when
someone
someone
figures
figures
out
out
how
how
to
to
make
make
quantum
quantum
computers
computers
work,
work
expect
expect
all
all
hell
hell
to
to
break
break
loose
loose
in
in
the
the
cybersecurity
cybersecurity
world.
world
At
at
the
the
beginning
beginning
of
of
this
this
video,
video
I
i
mentioned
mentioned
the
the
marching
marching
cubes
cubes
algorithm,
algorithm
but
but
it
it
deserves
deserves
a
a
closer
closer
look.
look
So
so
first,
first
we
we
start
start
with
with
a
a
3
3
d
d
scalar
scalar
field,
field
which
which
might
might
represent
represent
data
data
from
from
an
an
MRI
mri
machine.
machine
Each
each
point
point
in
in
the
the
3
3
d
d
space
space
is
is
represented
represented
by
by
a
a
single
single
number
number
or
or
a
a
scalar.
scalar
The
the
algorithm
algorithm
starts
starts
with
with
a
a
single
single
point,
point
then
then
takes
takes
its
its
8
8
neighboring
neighboring
locations
locations
to
to
form
form
an
an
cube,
cube
but
but
treats
treats
the
the
eight
eight
values
values
as
as
a
a
bit
bit
in
in
an
an
8
8
bit
bit
integer.
integer
This
this
results
results
in
in
256
256
different
different
possibilities,
possibilities
which
which
point
point
to
to
a
a
precalculated
precalculated
array
array
of
of
polygons.
polygons
The
the
algorithm
algorithm
marches
marches
through
through
each
each
point
point
to
to
create
create
a
a
3
3
d
d
mesh
mesh
that
that
can
can
be
be
used
used
in
in
3
3
d
d
software.
software
And
and
at
at
the
the
time,
time
this
this
was
was
really
really
cool
cool
because
because
as
as
MRI
mri
machines
machines
produce
produce
slices
slices
of
of
data
data
that
that
can
can
now
now
be
be
rendered
rendered
in
in
3
3
d.
d
In
in
modern
modern
times,
times
though,
though
we're
we're
often
often
dealing
dealing
with
with
distributed
distributed
systems
systems
in
in
the
the
cloud,
cloud
And
and
that
that
brings
brings
us
us
to
to
the
the
Byzantine
byzantine
generals
generals
problem.
problem
Imagine
imagine
you're
you're
a
a
general
general
in
in
the
the
Byzantine
byzantine
army.
army
You're
you're
camped
camped
around
around
a
a
city
city
with
with
a
a
few
few
other
other
generals
generals
with
with
plans
plans
to
to
attack
attack
it
it
the
the
next
next
morning.
morning
But
but
what
what
if
if
one
one
of
of
the
the
generals
generals
skitrunk
skitrunk
and
and
wakes
wakes
up
up
too
too
hungover
hungover
to
to
attack.
attack
The
the
entire
entire
system
system
could
could
collapse.
collapse
Computers
computers
have
have
the
the
same
same
problem.
problem
Sometimes
sometimes
they
they
might
might
fail
fail
or
or
be
be
infiltrated
infiltrated
by
by
hackers,
hackers
and
and
you
you
never
never
know
know
when
when
or
or
where
where
that's
that's
going
going
to
to
happen.
happen
Luckily,
luckily
algorithms
algorithms
like
like
PBFT
pbft
are
are
designed
designed
to
to
solve
solve
this.
this
They
they
can
can
keep
keep
a
a
distributed
distributed
network
network
working
working
properly
properly
even
even
if
if
up
up
to
to
1
1
third
third
of
of
its
its
nodes
nodes
go
go
haywire.
haywire
It
it
works
works
by
by
having
having
a
a
node
node
broadcast
broadcast
a
a
pre
pre
prepare
prepare
message
message
to
to
other
other
nodes,
nodes
indicating
indicating
its
its
readiness
readiness
to
to
execute
execute
some
some
code
code
that
that
will
will
change
change
the
the
system.
system
The
the
other
other
nodes
nodes
will
will
respond
respond
back
back
in
in
agreement.
agreement
Then
then
after
after
a
a
certain
certain
threshold,
threshold
a
a
consensus
consensus
is
is
formed.
formed
Once
once
there's
there's
a
a
consensus,
consensus
The
the
original
original
node
node
sends
sends
back
back
a
a
commit
commit
message
message
to
to
all
all
the
the
other
other
nodes,
nodes
which
which
can
can
then
then
all
all
execute
execute
the
the
changes,
changes
making
making
the
the
entire
entire
state
state
of
of
the
the
system
system
consistent.
consistent
Algorithms
algorithms
like
like
this
this
are
are
essential
essential
for
for
blockchain
blockchain
technology
technology
and
and
things
things
like
like
distributed
distributed
cloud
cloud
databases.
databases
What's
what's
really
really
cool
cool
about
about
algorithms,
algorithms
though,
though
is
is
that
that
they
they
can
can
also
also
reflect
reflect
nature,
nature
like
like
Boyd's
boyd's
artificial
artificial
life
life
program.
program
It
it
was
was
created
created
back
back
in
in
86
86
and
and
simulates
simulates
the
the
flocking
flocking
behavior
behavior
of
of
birds.
birds
What's
what's
so
so
cool
cool
about
about
it
it
is
is
that
that
it
it
demonstrates
demonstrates
the
the
emergent
emergent
complexity
complexity
or
or
beauty
beauty
that
that
we
we
get
get
out
out
of
of
just
just
a
a
few
few
simple
simple
rules.
rules
In
in
this
this
case,
case
the
the
birdoids
birdoids
have
have
three
three
rules.
rules
They
they
steer
steer
to
to
avoid
avoid
crowding,
crowding
they
they
steer
steer
towards
towards
the
the
average
average
heading
heading
of
of
the
the
flock,
flock
and
and
they
they
steer
steer
towards
towards
the
the
center
center
of
of
mass
mass
of
of
their
their
local
local
flockmates.
flockmates
The
the
end
end
result
result
are
are
these
these
intricate
intricate
patterns
patterns
that
that
weren't
weren't
programmed
programmed
directly,
directly
but
but
just
just
emerge
emerge
naturally.
naturally
But
but
finally,
finally
that
that
brings
brings
us
us
to
to
an
an
old
old
algorithm
algorithm
that
that
blew
blew
my
my
mind
mind
just
just
the
the
other
other
day
day
and
and
inspired
inspired
this
this
video,
video
Boyer
boyer
Moore
moore
string
string
search.
search
It's
it's
weird
weird
because
because
it
it
becomes
becomes
faster
faster
and
and
more
more
efficient
efficient
as
as
the
the
string
string
it's
it's
searching
searching
becomes
becomes
bigger.
bigger
That
that
seems
seems
impossible,
impossible
but
but
it
it
makes
makes
sense
sense
when
when
you
you
understand
understand
the
the
algorithm.
algorithm
It
it
scans
scans
skin's
skin's
text
text
from
from
right
right
to
to
left,
left
then
then
has
has
two
two
rules.
rules
When
when
it
it
encounters
encounters
a
a
bad
bad
character
character
not
not
found
found
in
in
the
the
search
search
pattern,
pattern
it
it
jumps
jumps
past
past
it
it
based
based
on
on
an
an
estimation
estimation
made
made
in
in
a
a
preprocess
preprocess
table.
table
Scale.
scale
Likewise,
likewise
if
if
it
it
finds
finds
a
a
partial
partial
match,
match
then
then
a
a
mismatch
mismatch
occurs.
occurs
It
it
has
has
a
a
separate
separate
pre
pre
calculated
calculated
table
table
that
that
maximizes
maximizes
the
the
number
number
of
of
characters
characters
it
it
can
can
safely
safely
skip.
skip
These
these
rules
rules
are
are
called
called
heuristics,
heuristics
which
which
are
are
like
like
functions
functions
that
that
are
are
not
not
guaranteed
guaranteed
to
to
be
be
perfect,
perfect
but
but
are
are
far
far
more
more
practical
practical
than
than
looping
looping
over
over
every
every
single
single
character.
character
In
in
this
this
case,
case
the
the
algorithm
algorithm
gets
gets
faster
faster
with
with
more
more
text
text
because
because
it's
it's
able
able
to
to
skip
skip
a
a
higher
higher
proportion
proportion
of
of
characters.
characters
And
and
if
if
you've
you've
ever
ever
wondered
wondered
why
why
GREP
grep
is
is
so
so
fast,
fast
you
you
have
have
this
this
algorithm
algorithm
to
to
thank.
thank
success
The speakers discuss the use of algorithms in scientific research, including random random algorithms like BOGO sort and BOGO sort to solve problems in scientific research, and the potential uses of these algorithms in optimizing algorithms and algorithms for algorithms. They also touch on the use of quantum algorithms in machine design and the future of digital security, including the use of random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random
10 weird algorithms
Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field? Yeah. I didn't think so. But back in 87, 2 programmers at General Electric did. They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans. Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk. Most algorithms belong in a dumpster, but some are fast, skin. Some are beautiful and some are so weird, they're indistinguishable from magic. Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world. 1st on the list, we have wave function collapse. One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle. It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build. It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically. Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity? We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly. What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities. It's the wave function. Then upon observation, it collapses into a particle. Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI. Speaking of which, AI is weird as hell. Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion. But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration. In artificial intelligence, the process is reversed. The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy. But first, you'll need to train model that can do this well. The diffusion algorithm works in 2 phases. In the forward phase, it gradually adds noise to an image step by step until it becomes completely random. In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image. When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models. It's highly compute intensive, but also works well on audio. And the next frontier is diffusion for video generation. But now Now let's talk about simulated annealing. One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions. Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others. Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects. The same idea is used in optimization algorithms to find the best answer or n a c of good answers. Imagine trying to find the highest point in a mountain range full of peaks and valleys. A simple hill climb algorithm won't work because there are many local peaks. Initially, the temperature sky allowing the algorithm to explore freely. As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution. The off here is exploration versus exploitation. But the reason I included this algorithm is because it's also a good way for beginners to learn how to code. Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in. But we can't talk about algorithms without talking about sorting. And the most ingenious sorting algorithm of all time is without a doubt, sleep sort. The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently. However, some random genius on 4 chan found a better way, but it's a bit unconventional. Here's what the code looks like in bash. It's incredibly simple. It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element. Then finally, after waking up, it prints that element. It's genius because it delegates the sorting to the CPU scheduler. It's also dumb and useless because it delegates sorting to the CPU scheduler. Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again. It's like playing the lottery. But what if we apply the same algorithm with quantum mechanics to the multiverse? If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes. That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted. The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier. Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it. That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem. It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature. But it's based on one simple mathematical reality. Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force. Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm. Prime factoring is pretty simple, but how this algorithm does it is where things get weird. It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel. The algorithm is legit, but so far, the biggest number ever factored is 21. Even IBM's state of the art Q System 1 fails when trying to factor the number 35. However, just recently, skin. The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm. Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world. At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look. So first, we start with a 3 d scalar field, which might represent data from an MRI machine. Each point in the 3 d space is represented by a single number or a scalar. The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer. This results in 256 different possibilities, which point to a precalculated array of polygons. The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software. And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d. In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem. Imagine you're a general in the Byzantine army. You're camped around a city with a few other generals with plans to attack it the next morning. But what if one of the generals skitrunk and wakes up too hungover to attack. The entire system could collapse. Computers have the same problem. Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen. Luckily, algorithms like PBFT are designed to solve this. They can keep a distributed network working properly even if up to 1 third of its nodes go haywire. It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system. The other nodes will respond back in agreement. Then after a certain threshold, a consensus is formed. Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent. Algorithms like this are essential for blockchain technology and things like distributed cloud databases. What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program. It was created back in 86 and simulates the flocking behavior of birds. What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules. In this case, the birdoids have three rules. They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates. The end result are these intricate patterns that weren't programmed directly, but just emerge naturally. But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search. It's weird because it becomes faster and more efficient as the string it's searching becomes bigger. That seems impossible, but it makes sense when you understand the algorithm. It scans skin's text from right to left, then has two rules. When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table. Scale. Likewise, if it finds a partial match, then a mismatch occurs. It has a separate pre calculated table that maximizes the number of characters it can safely skip. These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character. In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters. And if you've ever wondered why GREP is so fast, you have this algorithm to thank.
The speakers discuss the use of algorithms in scientific research, including random random algorithms like BOGO sort and BOGO sort to solve problems in scientific research, and the potential uses of these algorithms in optimizing algorithms and algorithms for algorithms. They also touch on the use of quantum algorithms in machine design and the future of digital security, including the use of random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random

        [INST]
        You are youtuber called Fireship you make engaging high-intensity and entertaining coding tutorials and tech news. 
        you covers a wide range of topics relevant to programmers, aiming to help them learn and improve their skills quickly.
        
        Given the title of the video : 10 weird algorithms 
        and a small summary : The speakers discuss the use of algorithms in scientific research, including random random algorithms like BOGO sort and BOGO sort to solve problems in scientific research, and the potential uses of these algorithms in optimizing algorithms and algorithms for algorithms. They also touch on the use of quantum algorithms in machine design and the future of digital security, including the use of random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random random
        [/INST]
        
        Generate the video : Have you ever woken up in the middle of the night in a panic wondering how to extract a polygonal mesh of an isosurface from a 3 dimensional discrete scalar field? Yeah. I didn't think so. But back in 87, 2 programmers at General Electric did. They created and patented the marching cubes algorithm, an algorithm that has likely saved countless lives by allowing doctors to visualize data from CT and MRI scans. Whenever you instruct a machine to solve a problem with code, you're creating an algorithm, a procedure for rearranging ones and zeros that can make animals talk and vacuums walk. Most algorithms belong in a dumpster, but some are fast, skin. Some are beautiful and some are so weird, they're indistinguishable from magic. Today, we'll look at 10 of the most interesting algorithms ever engineered sphere, and how they're used to solve very interesting problems in the real world. 1st on the list, we have wave function collapse. One of the weirdest things in all of science is the double slit experiment, where particles behave like a wave when you're not looking, but when you look, they suddenly collapse down to a particle. It seems counterintuitive, but it makes total sense when you realize we're living in a simulation and the universe wrote algorithm to cut down on its AWS build. It's an interesting concept to think about philosophically, but the general idea behind wave function collapse can also be implemented programmatically. Imagine we have a map for a video game, but what if this is a side scrolling game that can go on for eternity? We can't just make a bigger map, we need an algorithm to procedurally generate it on the fly. What's so weird is that we can take this initial map and think of it as being in the initial superposition of all possibilities. It's the wave function. Then upon observation, it collapses into a particle. Or in other words, it selects a random map tile but follows a consistent set of rules, like in this case, making sure that the roads are always connected, providing a random yet cohesive result and doesn't rely on any sort of modern generative AI. Speaking of which, AI is weird as hell. Diffusion is a machine learning algorithm originally developed at OpenAI and is the magic behind image generators like DALL E and Stable Diffusion. But the concept of diffusion actually comes from thermodynamics, where particles spread from areas of higher concentration to lower concentration. In artificial intelligence, the process is reversed. The algorithm starts by generating random noise, which would be like high entropy and thermodynamics, and gradually refines it to a structured image, which would be lower entropy. But first, you'll need to train model that can do this well. The diffusion algorithm works in 2 phases. In the forward phase, it gradually adds noise to an image step by step until it becomes completely random. In the second phase, the algorithm reverses this process, reconstructing it back into a coherent image. When the algorithm runs over millions of labeled images, we get a collection of weights that can be used to generate new images out of thin air, allowing us to build an infinite army OnlyFans models. It's highly compute intensive, but also works well on audio. And the next frontier is diffusion for video generation. But now Now let's talk about simulated annealing. One frustrating thing about programming is that for many problems, there's not just one solution, but many solutions. Like an Amazon warehouse has many different ways to organize its inventory, but some ways are more efficient than others. Annealing is a word that comes from metallurgy, where metals are skid heated up and cooled down over and over again to remove defects. The same idea is used in optimization algorithms to find the best answer or n a c of good answers. Imagine trying to find the highest point in a mountain range full of peaks and valleys. A simple hill climb algorithm won't work because there are many local peaks. Initially, the temperature sky allowing the algorithm to explore freely. As time goes on though, the temperature is lowered, which decreases the probability of accepting a worse solution. The off here is exploration versus exploitation. But the reason I included this algorithm is because it's also a good way for beginners to learn how to code. Initially, you start out exploring all kinds of different technologies and frameworks, then eventually you find one specific area to exploit and specialize in. But we can't talk about algorithms without talking about sorting. And the most ingenious sorting algorithm of all time is without a doubt, sleep sort. The majority of sane sorting algorithms out there use strategies like divide conquer to break up an array into subarrays where it can be sorted more efficiently. However, some random genius on 4 chan found a better way, but it's a bit unconventional. Here's what the code looks like in bash. It's incredibly simple. It loops over the array, and then for each element, it opens up a new thread that sleeps for the amount of time proportional to the value of its element. Then finally, after waking up, it prints that element. It's genius because it delegates the sorting to the CPU scheduler. It's also dumb and useless because it delegates sorting to the CPU scheduler. Speaking of which, you might be familiar with another useless sorting algorithm, BOGO sort, which tries to sort an array by randomly guessing over and over again. It's like playing the lottery. But what if we apply the same algorithm with quantum mechanics to the multiverse? If we're to trust multiverse science, we know that all possible outcomes exist in separate parallel universes. That means as a developer, if you find yourself with an unsorted array, there's or some other parallel universe where it is sorted. The technology isn't quite there yet, but if we could randomly observe these other universes to find the sorted array, we could then use a portal gun to travel to that universe, which would make our lives much easier. Although, we would obviously have to kill the version of ourself in that universe, but if it's a large array, quantum Bogosort might be worth it. That's purely hypothetical, but one of the most practical and goaded algorithms of all time is SCAR SA, a public key cryptosystem. It's essential for digital security, allowing people on the Internet to lock their mailboxes and sign their letters with a unique signature. But it's based on one simple mathematical reality. Multiplying large numbers to find 2 original large prime numbers is extremely difficult and time like it take your laptop 300,000,000,000,000 years to brute force. Unless quantum computers become a thing, and we can start leveraging Shor's algorithm, which can solve the integer factorization problem exponentially faster than any classical algorithm. Prime factoring is pretty simple, but how this algorithm does it is where things get weird. It relies on concepts like cubits, skits superposition and entanglement to perform massive amounts of calculations in parallel. The algorithm is legit, but so far, the biggest number ever factored is 21. Even IBM's state of the art Q System 1 fails when trying to factor the number 35. However, just recently, skin. The Chinese factored this big ass number with a quantum computer, but it uses a different algorithm that doesn't scale very well for large numbers unlike Shor's algorithm. Everything is safe for now, but when someone figures out how to make quantum computers work, expect all hell to break loose in the cybersecurity world. At the beginning of this video, I mentioned the marching cubes algorithm, but it deserves a closer look. So first, we start with a 3 d scalar field, which might represent data from an MRI machine. Each point in the 3 d space is represented by a single number or a scalar. The algorithm starts with a single point, then takes its 8 neighboring locations to form an cube, but treats the eight values as a bit in an 8 bit integer. This results in 256 different possibilities, which point to a precalculated array of polygons. The algorithm marches through each point to create a 3 d mesh that can be used in 3 d software. And at the time, this was really cool because as MRI machines produce slices of data that can now be rendered in 3 d. In modern times, though, we're often dealing with distributed systems in the cloud, And that brings us to the Byzantine generals problem. Imagine you're a general in the Byzantine army. You're camped around a city with a few other generals with plans to attack it the next morning. But what if one of the generals skitrunk and wakes up too hungover to attack. The entire system could collapse. Computers have the same problem. Sometimes they might fail or be infiltrated by hackers, and you never know when or where that's going to happen. Luckily, algorithms like PBFT are designed to solve this. They can keep a distributed network working properly even if up to 1 third of its nodes go haywire. It works by having a node broadcast a pre prepare message to other nodes, indicating its readiness to execute some code that will change the system. The other nodes will respond back in agreement. Then after a certain threshold, a consensus is formed. Once there's a consensus, The original node sends back a commit message to all the other nodes, which can then all execute the changes, making the entire state of the system consistent. Algorithms like this are essential for blockchain technology and things like distributed cloud databases. What's really cool about algorithms, though, is that they can also reflect nature, like Boyd's artificial life program. It was created back in 86 and simulates the flocking behavior of birds. What's so cool about it is that it demonstrates the emergent complexity or beauty that we get out of just a few simple rules. In this case, the birdoids have three rules. They steer to avoid crowding, they steer towards the average heading of the flock, and they steer towards the center of mass of their local flockmates. The end result are these intricate patterns that weren't programmed directly, but just emerge naturally. But finally, that brings us to an old algorithm that blew my mind just the other day and inspired this video, Boyer Moore string search. It's weird because it becomes faster and more efficient as the string it's searching becomes bigger. That seems impossible, but it makes sense when you understand the algorithm. It scans skin's text from right to left, then has two rules. When it encounters a bad character not found in the search pattern, it jumps past it based on an estimation made in a preprocess table. Scale. Likewise, if it finds a partial match, then a mismatch occurs. It has a separate pre calculated table that maximizes the number of characters it can safely skip. These rules are called heuristics, which are like functions that are not guaranteed to be perfect, but are far more practical than looping over every single character. In this case, the algorithm gets faster with more text because it's able to skip a higher proportion of characters. And if you've ever wondered why GREP is so fast, you have this algorithm to thank.
        