Latest / CyberSecurity Summary / Introduction to the Design and Analysis of Algorithms
Transcript
- 0:00Speaker 1: You know, you hear the word thrown around like everywhere
- 0:03Speaker 1: today constantly. I mean you hear it when people are
- 0:05Speaker 1: complaining about their social media feeds showing them weird ads,
- 0:09Speaker 1: or on the news when analysts talk about some sudden
- 0:13Speaker 1: flash crash in the.
- 0:14Speaker 2: Stock market, right, or even dating apps, yes.
- 0:17Speaker 1: Exactly, people are always like, oh, I can't get a
- 0:19Speaker 1: match the algorithm did it? Or I'm trying to beat
- 0:22Speaker 1: the algorithm.
- 0:23Speaker 2: Yeah, it's it really has taken on this sort of
- 0:26Speaker 2: mythical status, hasn't it.
- 0:28Speaker 1: It totally has.
- 0:29Speaker 2: It's treated almost like this magical entity, like a black
- 0:31Speaker 2: box that we just have to I don't know, accept
- 0:35Speaker 2: or revere or fear. We just blame it for things
- 0:38Speaker 2: we don't understand, assuming it has like its own personal agenda.
- 0:41Speaker 1: But the truth is an algorithm isn't magic. It doesn't
- 0:45Speaker 1: have an agenda. Okay, let's unpack this. I challenge you,
- 0:49Speaker 1: the listener, to just completely stop thinking of algorithms as
- 0:52Speaker 1: these mysterious thinking robots. Right.
- 0:54Speaker 2: Good luck with that, But yes.
- 0:56Speaker 1: I know it's hard. But instead I want you to
- 0:57Speaker 1: imagine them as recipes. Recipes, but not just any recipes,
- 1:02Speaker 1: like hyper specific, totally unforgiving recipes that cannot handle even
- 1:07Speaker 1: a single drop of ambiguity.
- 1:09Speaker 2: That is a phenomenal way to frame it. And really
- 1:12Speaker 2: the mission of our deep dive today is to get
- 1:15Speaker 2: inside that unforgiving recipe.
- 1:17Speaker 1: Yeah, to see how it actually works exactly.
- 1:19Speaker 2: We want to give you what the computer scientist George
- 1:21Speaker 2: Forsyth called general purpose mental tools, which remain serviceable for
- 1:26Speaker 2: a lifetime.
- 1:27Speaker 1: Oh.
- 1:28Speaker 2: I like that right, because mastering this topic isn't actually
- 1:31Speaker 2: about writing code in a dark basement. It's about a
- 1:34Speaker 2: revolutionary way of thinking, a.
- 1:36Speaker 1: Way of thinking that literally built the reality we live
- 1:39Speaker 1: in today.
- 1:40Speaker 2: He did, There's this brilliant quote from the writer David
- 1:42Speaker 2: Berlinski that I think captures this perfectly.
- 1:45Speaker 1: Oh yeah.
- 1:46Speaker 2: He noted that while the calculus made modern science possible,
- 1:49Speaker 2: it is the algorithm that is made possible the modern world.
- 1:52Speaker 2: You just cannot separate modern civilization from the algorithms that
- 1:55Speaker 2: run it.
- 1:56Speaker 1: Wow. I mean that is a massive claim, but a
- 1:58Speaker 1: true one. However, to understand and how these recipes built
- 2:02Speaker 1: the modern world, we first have to understand their anatomy.
- 2:05Speaker 2: We have to look at the nuts and bolts, right.
- 2:07Speaker 1: We need to move past the abstract buzzwords, So how
- 2:09Speaker 1: do you actually define it formally?
- 2:12Speaker 2: Well, in computer science, an algorithm is defined as a
- 2:15Speaker 2: sequence of unambiguous instructions for solving a.
- 2:18Speaker 1: Problem, Okay, unambiguous.
- 2:20Speaker 2: Right, which produces an output for any legitimate input in
- 2:23Speaker 2: a finite amount of time.
- 2:25Speaker 1: So I want to focus on that word unambiguous because
- 2:28Speaker 1: it means absolutely no guesswork, right, zero guesswork. The computer
- 2:32Speaker 1: pioneer Donald Nuth had a great philosophy about this. You
- 2:36Speaker 1: know how people say you don't really understand something until
- 2:39Speaker 1: you can teach it to a five year old.
- 2:40Speaker 2: Right, Yeah, the classic Fineman kind of thing, exactly.
- 2:43Speaker 1: Well, Nuth took it a step further. He said, you
- 2:45Speaker 1: don't really understand something until you can teach it to
- 2:48Speaker 1: a computer because.
- 2:49Speaker 2: The computer has zero common sense, none, zero intuition. Like,
- 2:53Speaker 2: if you tell a human chef to add a pinch
- 2:55Speaker 2: of salt, they know what that means based on I
- 2:59Speaker 2: don't know, experiencing context.
- 3:01Speaker 1: Yeah, they just grab some salt.
- 3:03Speaker 2: But if you tell a computer to add a pinch,
- 3:05Speaker 2: it crashes. It needs to know exactly how many milligram
- 3:09Speaker 2: delivered it, what velocity, under what specific temperature conditions?
- 3:13Speaker 1: Right, It needs the exact mass exactly.
- 3:15Speaker 2: The precision inherently imposed by algorithmic thinking forces you to
- 3:19Speaker 2: truly deeply understand the problem you're trying to solve. You
- 3:23Speaker 2: just can't gloss over the details.
- 3:25Speaker 1: So let's bring this down to earth with a concrete example,
- 3:28Speaker 1: a problem most of us probably remember dreading.
- 3:30Speaker 2: In middle school and boy math class.
- 3:33Speaker 1: Yep, finding the greatest common divisor or GCD of two numbers.
- 3:38Speaker 1: Let's use sixty and twenty four.
- 3:40Speaker 2: Okay, so we're looking for the largest integer that divides
- 3:42Speaker 2: perfectly into both sixty and twenty four without leaving a
- 3:45Speaker 2: remainder exactly.
- 3:46Speaker 1: And this is a great starting point because it highlights
- 3:49Speaker 1: something crucial about this field. There isn't just one algorithm
- 3:52Speaker 1: for a problem, oh totally.
- 3:54Speaker 2: The same mathematical problem can be solved in multiple ways,
- 3:57Speaker 2: and those ways can differ dramatically in their sophistication, their speed,
- 4:02Speaker 2: and just their elegance.
- 4:03Speaker 1: Right, So let's walk through three different ways to solve
- 4:06Speaker 1: this exact same GCD problem. Method one is what we
- 4:09Speaker 1: call the brute force way consecutive IAGA.
- 4:12Speaker 2: Checking very literal name very You.
- 4:15Speaker 1: Just start with the smaller of the two numbers in
- 4:17Speaker 1: this case twenty four, and you check if it divides
- 4:19Speaker 1: evenly into.
- 4:20Speaker 2: Sixty, which obviously it doesn't. Sixty divided by twenty four leaves.
- 4:24Speaker 1: A remainder, right, so you step down. You try twenty three.
- 4:28Speaker 1: Does that divide into sixty and twenty four without a remainder?
- 4:31Speaker 2: No?
- 4:31Speaker 1: No, you try twenty two, then twenty one. You just
- 4:34Speaker 1: keep blindly subtracting one and checking every single number until
- 4:37Speaker 1: you finally.
- 4:38Speaker 2: Hit twelve and twelve works.
- 4:39Speaker 1: Twelve divides into sixty exactly five times, and it divides
- 4:43Speaker 1: into twenty four exactly two times. Bingo.
- 4:47Speaker 2: I mean it works, and it technically it fits the
- 4:49Speaker 2: definition of an algorithm because it will always give you
- 4:52Speaker 2: an answer and a finite amount of time.
- 4:53Speaker 1: Yet it's slow.
- 4:54Speaker 2: It is incredibly inefficient. Imagine if those two numbers weren't
- 4:57Speaker 2: sixty and twenty four but like two prime numbers in
- 5:00Speaker 2: the billions gosh, which by the way, is exactly what
- 5:03Speaker 2: modern encryption uses. A computer would be counting backwards and
- 5:07Speaker 2: checking remainders for days.
- 5:09Speaker 1: Yeah, we definitely need something better. So method two. This
- 5:13Speaker 1: is the one the Greek mathematician Euclid came up with
- 5:16Speaker 1: in the third century BC.
- 5:17Speaker 2: An absolute classic.
- 5:18Speaker 1: It is elegant, it is lightning fast, and it uses
- 5:22Speaker 1: a clever trick of repeated division and remainders.
- 5:25Speaker 2: Euclid's algorithm is just a masterpiece of logic. Instead of
- 5:28Speaker 2: stubbornly counting down one by one, you take the larger
- 5:31Speaker 2: number sixty and divide it by the smaller number twenty four.
- 5:35Speaker 1: Okay, so sixty divided by twenty fours two with a
- 5:38Speaker 1: remainder of twelve.
- 5:39Speaker 2: Right now here is the magic trick. You throw the
- 5:41Speaker 2: sixty in the garbage. Just toss it, just toss it.
- 5:44Speaker 2: You take your old divisor twenty four, and you divide
- 5:46Speaker 2: it by your new remainder twelve.
- 5:48Speaker 1: Oh okay, So twenty four divided by twelve is two
- 5:51Speaker 1: with a remainder of exactly zero.
- 5:53Speaker 2: And the moment your remainder hit zero, your current divisor
- 5:56Speaker 2: is your answer. Wow, so twelve is the greatest common divisor.
- 5:59Speaker 2: You got in just two quick steps instead of checking
- 6:01Speaker 2: a dozen different numbers.
- 6:02Speaker 1: That is so much faster.
- 6:04Speaker 2: Euclid realized that the greatest common divisor of the original
- 6:07Speaker 2: numbers is mathematically identical to the greatest common divisor of
- 6:13Speaker 2: the smaller number and the remainder. It systematically rapidly shrinks
- 6:18Speaker 2: the problem down.
- 6:19Speaker 1: It's beautiful, honestly. But then there's method three, the middle
- 6:23Speaker 1: school procedure. Ah, yes, this is how you, the listener,
- 6:26Speaker 1: were probably taught to do it on a chalkboard. Step one,
- 6:30Speaker 1: you find the prime factors of sixty, so that's two
- 6:32Speaker 1: times two times three times five.
- 6:34Speaker 2: Right.
- 6:35Speaker 1: Step two find the prime factors of twenty four, so
- 6:38Speaker 1: two times two times two times three.
- 6:39Speaker 2: And then step three you multiply all the common factors together, which.
- 6:42Speaker 1: Gives you the common two and other common two and
- 6:44Speaker 1: a common three. Multiply them and you get twelve.
- 6:46Speaker 2: Makes perfect sense for a human, right.
- 6:48Speaker 1: But here's where it gets really interesting, because I am
- 6:51Speaker 1: going to push back hard on our middle school math
- 6:54Speaker 1: teachers today. Oh that procedure. It isn't actually a legitimate algorithm.
- 6:58Speaker 2: Oh absolutely not. It's really not. And this circles perfectly
- 7:01Speaker 2: back to our definition of unambiguous.
- 7:04Speaker 1: Exactly because the instruction find prime factors is a massive cheat.
- 7:08Speaker 1: It is unless your teacher handed you a perfect, precalculated
- 7:13Speaker 1: list of every single prime number in existence. How does
- 7:17Speaker 1: the computer know what a prime number is? It doesn't
- 7:19Speaker 1: you can't just tell machine, hey, just find the primes.
- 7:22Speaker 1: You have to give it a recipe for finding the
- 7:24Speaker 1: primes first.
- 7:25Speaker 2: Right, And this raise is an important question. How do
- 7:27Speaker 2: we actually eliminate that ambiguity? Because finding primes is notoriously
- 7:31Speaker 2: difficult it is. The answer actually dates back to around
- 7:34Speaker 2: two hundred PC, with a method called the sieve of Eritosthenes.
- 7:38Speaker 1: The sieve I love this concept. It is the perfect
- 7:42Speaker 1: mechanical solution to the ambiguity of finding primes.
- 7:46Speaker 2: It's brilliant. Imagine you need to find all the prime
- 7:49Speaker 2: numbers up to one hundred. You don't try to calculate
- 7:52Speaker 2: primes directly. Instead, you eliminate everything that isn't a prime.
- 7:56Speaker 2: So you write down all the numbers from two to
- 7:58Speaker 2: one hundred on a giant p paper.
- 8:00Speaker 1: I'm visualizing it.
- 8:01Speaker 2: You start with the first number, two, You keep it
- 8:04Speaker 2: because it's prime, but then you systematically cross out every
- 8:07Speaker 2: single multiple of two on your list four, six, eight, ten,
- 8:12Speaker 2: they're all gone, got it.
- 8:14Speaker 1: Then you move to the next number on the paper
- 8:16Speaker 1: that hasn't been crossed out, which is three. Right, you
- 8:18Speaker 1: circle it and you cross out every multiple of three.
- 8:21Speaker 1: Six has already gone. So you cross out nine to twelve, fifteen,
- 8:24Speaker 1: and you.
- 8:25Speaker 2: Just repeat the sweeping process. By the time you reach
- 8:28Speaker 2: the end of the paper, the numbers that survives the sieve,
- 8:32Speaker 2: the ones that haven't been crossed out, are You're guaranteed
- 8:34Speaker 2: prime numbers.
- 8:35Speaker 1: It's just a completely unambiguous, zero guesswork set of mechanical instructions.
- 8:41Speaker 2: Exactly. You can hand that to a dumb machine and
- 8:43Speaker 2: it'll execute it flawlessly.
- 8:45Speaker 1: But wait, if I'm understanding this, Practically writing down all
- 8:48Speaker 1: those numbers to do the sieve of aritosites requires a
- 8:51Speaker 1: massive piece of paper.
- 8:52Speaker 2: Yes it does.
- 8:53Speaker 1: If a computer is doing this for numbers in the trillions,
- 8:56Speaker 1: it has to store all those trillions of numbers in
- 8:58Speaker 1: its memory just to cross them out, which naturally leads
- 9:01Speaker 1: us to a huge problem. We don't have infinite memory.
- 9:04Speaker 2: We really don't. And that physical limitation brings us to
- 9:07Speaker 2: the blueprint of problem solving, moving from just knowing what
- 9:11Speaker 2: an algorithm is to the actual engineering process of creating
- 9:14Speaker 2: one in the real world.
- 9:15Speaker 1: Because it's not just theoretical math anymore.
- 9:18Speaker 2: Right. The first step is always deeply understanding the problem, yes,
- 9:22Speaker 2: but the second step is ascertaining the exact capabilities of
- 9:25Speaker 2: your computational device.
- 9:27Speaker 1: Because algorithms don't just float in the ether. They run
- 9:31Speaker 1: on physical hardware, and for most of the modern era,
- 9:34Speaker 1: that hardware is based on the von Neuman ram model.
- 9:36Speaker 1: Right the random access machine yes.
- 9:38Speaker 2: Named after the brilliant polymath John von Neuman. The core
- 9:43Speaker 2: assumption of the von Neuman model is that instructions are
- 9:46Speaker 2: executed sequentially, one after the other, one operation at a time,
- 9:50Speaker 2: moving data back and forth between the processor and the memory.
- 9:54Speaker 2: That architectural bottleneck completely dictates how you design your steps.
- 9:58Speaker 1: It's like a traffic jam pretty.
- 9:59Speaker 2: Much, and once you understand that environment, you slam headfirst
- 10:03Speaker 2: into the fundamental tension of all algorithm design, the brutal
- 10:06Speaker 2: trade off between time efficiency and space efficiency.
- 10:09Speaker 1: Speed versus memory always.
- 10:11Speaker 2: Sometimes you can design an algorithm to run incredibly fast,
- 10:14Speaker 2: but it achieves that speed by hogging a massive amount
- 10:17Speaker 2: of computer memory to store all its intermediate calculations.
- 10:21Speaker 1: Like our giant piece of paper for the sieve.
- 10:23Speaker 2: Exactly like that. Other times you can design an algorithm
- 10:26Speaker 2: to use almost zero extra memory, but the trade off
- 10:30Speaker 2: is that it might take twice as long to process
- 10:33Speaker 2: because it has to constantly recalculate things instead of looking
- 10:37Speaker 2: them up.
- 10:37Speaker 1: You rarely get to have both, almost never. It's an
- 10:41Speaker 1: agonizing balancing act for software engineers, and it's important to
- 10:44Speaker 1: realize that solving this isn't just about adding more and
- 10:47Speaker 1: more complex code to make it work right.
- 10:49Speaker 2: Quite the opposite. Actually, the best algorithms are often the leanest.
- 10:53Speaker 2: There's a wonderful quote from the aviation pioneer and twine
- 10:57Speaker 2: Deissant Zuperrie that computer scientists love.
- 11:00Speaker 1: Oh, I think I know this one.
- 11:02Speaker 2: He said, A designer knows he has arrived at perfection
- 11:05Speaker 2: not when there is no longer anything to add, but
- 11:07Speaker 2: when there is no longer anything to take away.
- 11:09Speaker 1: Carving away the unnecessary steps just pure efficiency. But I
- 11:13Speaker 1: have to ask what happens when taking away isn't enough?
- 11:15Speaker 2: What do you mean? Like?
- 11:16Speaker 1: What happens when a problem is just mathematically too big,
- 11:19Speaker 1: even for the most perfectly optimized code.
- 11:21Speaker 2: Well, what's fascinating here is that algorithm designers will sometimes
- 11:25Speaker 2: intentionally choose an approximation algorithm over an exact one.
- 11:30Speaker 1: Wait, wait, I want to make sure I'm hearing this right.
- 11:32Speaker 1: They write code to intentionally be less accurate on purpose.
- 11:36Speaker 2: Yes, specifically when dealing with problems that are intrinsically so
- 11:41Speaker 2: complex that calculating the exact perfect answer would take a
- 11:45Speaker 2: supercomputer thousands of years.
- 11:48Speaker 1: Okay, I actually have an analogy for this.
- 11:49Speaker 2: Let's hear it.
- 11:50Speaker 1: It's like packing a car for a family cross country
- 11:53Speaker 1: road trip. Oh one nightmare, complete nightmare. So if you
- 11:56Speaker 1: use an exact algorithm, you are trying to calculate every
- 11:59Speaker 1: single mathematical geometric combination of luggage coolers, sleeping bags, and
- 12:03Speaker 1: backpacks to utilize every square millimeter of the trunk.
- 12:08Speaker 2: Perfectly, which would take forever.
- 12:09Speaker 1: Right, calculating that absolute perfection might take you ten years
- 12:13Speaker 1: of standing in the driveway with the tape measure.
- 12:15Speaker 2: And the kids are screaming in the back.
- 12:16Speaker 1: Seat exactly, So an approximate algorithm just throws the heavy
- 12:20Speaker 1: bags in the bottom, shoves the soft bags in the
- 12:23Speaker 1: gaps so it fits, you know, good enough. You might
- 12:25Speaker 1: lose a tiny bit of trunk space, but you actually
- 12:28Speaker 1: get to back out of the driveway and get on
- 12:30Speaker 1: the road.
- 12:30Speaker 2: Today. That is an excellent way to visualize it, because
- 12:34Speaker 2: in computing we face incredibly vital real world problems like
- 12:41Speaker 2: routing global shipping fleets or folding proteins for medical.
- 12:44Speaker 1: Research huge problems.
- 12:46Speaker 2: Right, we're finding the absolute optimal answer is computationally impossible
- 12:51Speaker 2: in a human lifetime. We will gladly accept an answer
- 12:54Speaker 2: that is ninety eight percent optimal. If the approximate algorithm
- 12:57Speaker 2: can give it to us in five seconds.
- 12:59Speaker 1: That makes totally So. We have this engineering blueprint. We
- 13:02Speaker 1: know how to think about our hardware constraints' time space,
- 13:05Speaker 1: deciding between exactness and approximation. Right, but what are the
- 13:09Speaker 1: actual materials we use to build these things? If we
- 13:11Speaker 1: go back to the car packing analogy, we know we
- 13:13Speaker 1: want to pack fast, but what kind of containers are
- 13:15Speaker 1: we actually using? Hard shell suitcases, soft stuffle bags.
- 13:19Speaker 2: Because algorithms don't exist in a vacuum.
- 13:21Speaker 1: Exactly, they have to manipulate data.
- 13:23Speaker 2: This is where we get into the physical architecture of information.
- 13:26Speaker 2: There is a famous programming proverb by the Swiss computer
- 13:29Speaker 2: scientist Niklaus Worth. He said, algorithms plus data structures equals programs.
- 13:35Speaker 1: Okay, algorithms plus data structures.
- 13:37Speaker 2: You cannot separate the logical instructions from the physical way
- 13:41Speaker 2: that data is organized in the computer's memory.
- 13:43Speaker 1: Let's talk about those data structures then, these are the
- 13:46Speaker 1: virtual containers holding the information, and I really want to
- 13:50Speaker 1: understand why we choose different ones. Let's start with arrays
- 13:54Speaker 1: versus linked lists.
- 13:55Speaker 2: Okay, think of an array as a rigid, contiguous block
- 13:59Speaker 2: of memory. It's like a row of townhouses built exactly
- 14:01Speaker 2: next to each other.
- 14:02Speaker 1: Okay, a row of houses.
- 14:04Speaker 2: If you know the address of the first house and
- 14:06Speaker 2: you want to visit house number fifty, you can calculate
- 14:09Speaker 2: exactly where it is and jump straight to it. Access
- 14:12Speaker 2: is incredibly.
- 14:12Speaker 1: Fast because it's perfectly sequential exactly.
- 14:15Speaker 2: This is why screens use a raise to store pixel data.
- 14:18Speaker 2: They need to update millions of pixels instantly. But arrays
- 14:22Speaker 2: are totally.
- 14:22Speaker 1: Rigid, right because if I suddenly want to build a
- 14:25Speaker 1: new townhouse right in the middle of the block between
- 14:29Speaker 1: house ten and eleven, I can't Nope, I'd have to
- 14:31Speaker 1: physically pick up and move every single house from eleven
- 14:35Speaker 1: to fifty down one plot just to make room, which
- 14:39Speaker 1: takes massive computing time.
- 14:41Speaker 2: Precisely, which is why we have the alternative a length list.
- 14:45Speaker 2: A link list is more like a scavenger hunt spread
- 14:47Speaker 2: all over a city, and a gavenger hunt, yeah, the
- 14:50Speaker 2: data isn't stored together. It's just scattered in whatever random
- 14:54Speaker 2: memory spaces happen to be empty. Yeah, but each piece
- 14:57Speaker 2: of data contains a pointer, a clue to selling the
- 15:00Speaker 2: computer the exact address of the next piece of data.
- 15:03Speaker 1: Oh so it's incredibly flexible.
- 15:05Speaker 2: Extremely you want to insert something new in the middle,
- 15:07Speaker 2: you don't have to move anything. You just changed one
- 15:09Speaker 2: clue to point to the new item and have the
- 15:12Speaker 2: new item point to the rest of the list.
- 15:13Speaker 1: That's so clever.
- 15:14Speaker 2: But the trade off is speed. If you want item
- 15:16Speaker 2: number fifty, you can't just jump to it. You had
- 15:18Speaker 2: started item one, read the clue to find item two,
- 15:21Speaker 2: read the clue to fined item three, all the way down.
- 15:24Speaker 1: Ah. So ras give you lightning fast access but rigid structure,
- 15:29Speaker 1: while link lists give you flexible memory but slower search times.
- 15:33Speaker 2: Exactly, it perfectly illustrates that time versus space trade off.
- 15:37Speaker 1: Okay, what about structures that dictate how data actually behaves.
- 15:41Speaker 1: Let's say I'm typing a document on my computer and
- 15:44Speaker 1: I make a mistake, so I hit the undue button.
- 15:47Speaker 1: How does the computer know what to undo?
- 15:49Speaker 2: That behavior is governed by a data structure called a stack.
- 15:53Speaker 2: A stack operates on a LiPo principle last in, first out.
- 15:57Speaker 1: Last and first out like a stack of plates.
- 15:58Speaker 2: Exactly. Think about your web browser's back button history. Every
- 16:03Speaker 2: time you click a new link, that new web page
- 16:05Speaker 2: is placed on the top of your history stack. When
- 16:07Speaker 2: you hit the back button, the computer pulls the web
- 16:10Speaker 2: page off the very top of the stack. The last
- 16:12Speaker 2: page you visited is the first one you returned to.
- 16:14Speaker 1: Okay, but what if I'm queuing up a bunch of
- 16:16Speaker 1: songs on a Spotify playlist. I don't want the last
- 16:18Speaker 1: song I added to play first. I want the first
- 16:20Speaker 1: song I picked.
- 16:21Speaker 2: To play first, and that requires a queue. A queue
- 16:23Speaker 2: is the exact opposite of a stack. It's fifo, first in,
- 16:26Speaker 2: first out, like a.
- 16:27Speaker 1: Lion at the grocery store.
- 16:28Speaker 2: Yeah, it's like that. Or a virtual waiting room for
- 16:31Speaker 2: buying concert tickets online. The first person who logs into
- 16:35Speaker 2: the queue is the first person who gets to buy
- 16:37Speaker 2: a ticket. The algorithm uses a cue structure to guarantee
- 16:40Speaker 2: fairness and sequence.
- 16:42Speaker 1: Okay, so we have arrays, lists, stacks, queues, but all
- 16:46Speaker 1: of these seem very linear, very one dimensional. How do
- 16:51Speaker 1: algorithms handle complex relationships? Like how does Google maps figure
- 16:55Speaker 1: out the best roads, or Facebook know who my mutual
- 16:58Speaker 1: friends are?
- 16:58Speaker 2: Well if we connect this to the bigger picture. To
- 17:01Speaker 2: map relationships, algorithms use a massive structure called a graph.
- 17:05Speaker 2: A graph right, A graph is a collection of points
- 17:07Speaker 2: called vertices, connected by lines called edges. Vertices could be cities,
- 17:11Speaker 2: and edges could be the highways connecting them. Or vertices
- 17:14Speaker 2: are users and edges are their friendships.
- 17:16Speaker 1: But how does a computer actually store a graph in
- 17:18Speaker 1: its memory?
- 17:19Speaker 2: This is where data structure choice becomes make or break.
- 17:22Speaker 2: You could use an adjacency matrix. Imagine a giant axcel
- 17:26Speaker 2: grid where every single user on the platform has their
- 17:28Speaker 2: own row and their own column. If you are friends
- 17:31Speaker 2: with someone, the computer puts a one in the box
- 17:35Speaker 2: where your row and their column intersect.
- 17:37Speaker 1: Wait, but if a social network has a billion users,
- 17:40Speaker 1: that grid has a quintillion boxes.
- 17:43Speaker 2: Yep.
- 17:43Speaker 1: And if I only have five hundred friends, that means
- 17:45Speaker 1: my row has five hundred ones and nine hundred and
- 17:49Speaker 1: ninety nine million, nine hundred and ninety nine thousand, five
- 17:52Speaker 1: hundred zeros.
- 17:53Speaker 2: It's a lot of zeros.
- 17:54Speaker 1: That matrix would be a massive grid filled almost entirely
- 17:57Speaker 1: with empty.
- 17:58Speaker 2: Zeros, which would waste catastrophic amounts of memory. Yeah, so instead,
- 18:01Speaker 2: for a sparse graph like that, an engineer would choose
- 18:04Speaker 2: an adjacency list.
- 18:05Speaker 1: Okay, what's that.
- 18:06Speaker 2: It's basically just a linked list for each user containing
- 18:09Speaker 2: only the names of their actual friends. No wasted space
- 18:13Speaker 2: storing millions of zeros.
- 18:14Speaker 1: Oh wow. The container completely dictates the efficiency, it really does,
- 18:19Speaker 1: and that efficiency is crucial because the problems we run
- 18:21Speaker 1: on these graphs can be notoriously terrifically difficult. I'm thinking
- 18:24Speaker 1: specifically about combinatorial problem. Oh.
- 18:27Speaker 2: Combinatorial problems are the absolute beasts of computer science.
- 18:30Speaker 1: The beasts huh oh yeah.
- 18:32Speaker 2: They ask you to find a specific combination or sequence
- 18:36Speaker 2: that satisfies a strict constraint, usually finding a minimum or
- 18:40Speaker 2: maximum value.
- 18:41Speaker 1: The classic one I read about is the traveling salesman problem. Yes,
- 18:44Speaker 1: you have a delivery driver who needs to drop off
- 18:47Speaker 1: packages in fifty different cities. What is the absolute shortest
- 18:51Speaker 1: driving route that visits every single city exactly once and
- 18:55Speaker 1: returns to the warehouse.
- 18:56Speaker 2: It sounds like a simple rooting question, right, but the
- 18:59Speaker 2: math is terrifying.
- 19:00Speaker 1: Really, just fifty cities or just fifty cities?
- 19:03Speaker 2: The number of possible routes grows factorially, it quickly surpasses
- 19:08Speaker 2: the total number of atoms in the observable universe.
- 19:11Speaker 1: Wait, really, that's insane.
- 19:13Speaker 2: The options explode so violently that no computer present or
- 19:16Speaker 2: future could ever calculate them all to find the absolute
- 19:19Speaker 2: perfect one. This is exactly where those approximation algorithms we
- 19:23Speaker 2: talked about with the car trunk become absolutely essential.
- 19:25Speaker 1: Because you just have to get a route that's good enough.
- 19:27Speaker 2: Exactly.
- 19:28Speaker 1: But not all problems are universe breaking. I want to
- 19:31Speaker 1: circle back to something incredibly mundane sorting.
- 19:34Speaker 2: Sorting just putting things.
- 19:36Speaker 1: In order, alphabetizing a list of names, or ranking Amazon
- 19:40Speaker 1: items by price. I know there are dozens of sorting
- 19:42Speaker 1: algorithms with weird names out there, bubble sort, merge sort,
- 19:47Speaker 1: quick sort.
- 19:48Speaker 2: Oh yeah, tons of them.
- 19:50Speaker 1: And here's where I have to admit some confusion. If
- 19:53Speaker 1: sorting is such a common problem, why haven't we just
- 19:56Speaker 1: found the single, best, fastest sorting algorithm, crowned at the winner,
- 20:01Speaker 1: and thrown all the others in the trash.
- 20:03Speaker 2: It's a fantastic question, and it comes right back to
- 20:05Speaker 2: the idea that there is no universal silver bullet in
- 20:08Speaker 2: algorithmic design. Every single algorithm has trade offs depending on
- 20:12Speaker 2: the context of the data.
- 20:14Speaker 1: Give me a real world scenario.
- 20:15Speaker 2: We let's say you have an algorithm like quicksort. It
- 20:17Speaker 2: is blisteringly fast if you hand it a totally random,
- 20:20Speaker 2: jumbled up list of data. Okay, But ironically, if you
- 20:23Speaker 2: feed quicksort a list that is already almost perfectly sorted,
- 20:26Speaker 2: say just one or two items out of place, the
- 20:29Speaker 2: algorithm actually chokes.
- 20:31Speaker 1: It gets slower.
- 20:32Speaker 2: Oh yeah, his logic gets tangled up, and there's incredibly slow.
- 20:35Speaker 2: In that specific case, a seemingly inferior algorithm like insertion
- 20:39Speaker 2: sort will beat it effortlessly. Wow.
- 20:42Speaker 1: And earlier we talked about the space versus time trade off.
- 20:45Speaker 1: Does that apply to sorting too?
- 20:47Speaker 2: Absolutely. Some of the fastest sorting algorithms in the world
- 20:50Speaker 2: are memory hogs. They require creating a complete duplicate of
- 20:54Speaker 2: your data set while they sort it.
- 20:57Speaker 1: But if your computer's RAM is already maxed out.
- 21:00Speaker 2: Literally can't do that. You are forced to use what
- 21:03Speaker 2: we call an in place algorithm. Mean it sorts the
- 21:06Speaker 2: data by just swapping items around within the original list
- 21:09Speaker 2: using zero extra memory. It might be slightly slower, but
- 21:13Speaker 2: it won't crash machine.
- 21:14Speaker 1: I've also heard the term stable algorithm. What does that
- 21:17Speaker 1: mean in the context of sorting?
- 21:18Speaker 2: A stable sorting algorithm perfectly preserves the original relative order
- 21:22Speaker 2: of equal elements.
- 21:23Speaker 1: I'm going to need an example for that one.
- 21:25Speaker 2: Okay. Imagine you have a massive spreadsheet of students and
- 21:29Speaker 2: they are already perfectly sorted alphabetically by their last name.
- 21:33Speaker 2: Now you highlight the whole sheet until the computer to
- 21:36Speaker 2: resort everyone by their grade point average.
- 21:38Speaker 1: Okay, I'm with you.
- 21:40Speaker 2: A stable algorithm ensures that all the students who share
- 21:43Speaker 2: a three point five GPA will still be in flawless
- 21:46Speaker 2: alphabetical order within that specific GPA bracket. Oh, I say,
- 21:50Speaker 2: an unstable algorithm, even if it's faster, we'll just throw
- 21:54Speaker 2: them into the GPA bracket randomly, completely ruining your previous
- 21:58Speaker 2: alphabetical sorting.
- 21:59Speaker 1: So the best algorithm depends entirely on whether your data
- 22:02Speaker 1: is almost sorted, how much memory you have, and whether
- 22:05Speaker 1: you need stability. You have to deeply know your data,
- 22:08Speaker 1: know your constraints, and know your toolbox precisely.
- 22:11Speaker 2: You have to match the recipe to the reality of
- 22:14Speaker 2: the kitchen.
- 22:15Speaker 1: So what does this all mean. We've talked about euclid
- 22:18Speaker 1: dividing numbers, about packing car trunks, about web browser history stacks,
- 22:22Speaker 1: and universe breaking traveling salesmen.
- 22:24Speaker 2: We've covered a lot, we really have.
- 22:26Speaker 1: But how does this deep dive into the architecture of
- 22:30Speaker 1: computer algorithms actually help you, the listener in your everyday
- 22:35Speaker 1: intellectual life.
- 22:36Speaker 2: Well, it goes right back to that George Forsyth quote
- 22:39Speaker 2: from the very beginning about mental tools. Learning algorithmic design
- 22:43Speaker 2: techniques is like learning to fish. When you train your
- 22:46Speaker 2: brain to break down problems algorithmically, you are learning how
- 22:50Speaker 2: to look at any complex real world situation, whether it's
- 22:54Speaker 2: managing amounts of business logistics, chain plotting a novel, or
- 22:58Speaker 2: just organizing your personal finance and break it into unambiguous,
- 23:02Speaker 2: actionable steps.
- 23:03Speaker 1: It forces precision, I think in an era where we
- 23:05Speaker 1: are all completely overwhelmed by information overload, Algorithmic thinking is
- 23:10Speaker 1: like the ultimate mental filter.
- 23:11Speaker 2: It really is.
- 23:12Speaker 1: It makes you pause and ask, what is the exact
- 23:15Speaker 1: factual input here, what is the exact defined output I need?
- 23:19Speaker 1: And what is the step by step logical process to
- 23:22Speaker 1: get from A to B? Without relying on magic assumptions
- 23:25Speaker 1: or vague guesses.
- 23:26Speaker 2: It ruthlessly strips away the ambiguity, and stripping away ambiguity
- 23:30Speaker 2: leads to a deeper, truer understanding of whatever subject you
- 23:33Speaker 2: apply it to. It forces intellectual honesty.
- 23:36Speaker 1: Just when you think algorithmic thinking is the key to
- 23:38Speaker 1: mastering the universe, there is a catch. And this is
- 23:41Speaker 1: how we're going to wrap up today.
- 23:42Speaker 2: Yes, for all the immense power of algorithms, for all
- 23:45Speaker 2: the ways they have fundamentally built the modern world, they
- 23:48Speaker 2: have hard, terrifying mathematical limits. Wait really, Yeah, we have
- 23:52Speaker 2: this collective cultural assumption that if we just build a
- 23:55Speaker 2: fast enough quantum computer or write a clever enough AI algorithm,
- 24:00Speaker 2: you will eventually be able to solve any problem in
- 24:02Speaker 2: the universe.
- 24:02Speaker 1: Right, that's what everyone says.
- 24:03Speaker 2: But that is demonstrably mathematically.
- 24:06Speaker 1: False, because there are problems that are literally unsolvable.
- 24:09Speaker 2: They are called undecidable problems. And to be clear, these
- 24:12Speaker 2: aren't vague subjective philosophical questions like what is the meaning
- 24:18Speaker 2: of life?
- 24:18Speaker 1: Right? Not poetry?
- 24:20Speaker 2: No, These are well defined, unambiguously stated, mathematical logic problems
- 24:25Speaker 2: with simple yes or no answers that have been rigorously
- 24:28Speaker 2: proven to be unsolvable by any algorithm.
- 24:32Speaker 1: Ever, that is genuinely mind bending.
- 24:34Speaker 2: The most famous examples related to the halting problem basically
- 24:37Speaker 2: asking an algorithm to examine another piece of code and
- 24:40Speaker 2: tell you a simple yes or no. Will this code
- 24:43Speaker 2: eventually finish running or will it get stuck in an
- 24:46Speaker 2: infinite loop forever?
- 24:47Speaker 1: And it can't do that.
- 24:48Speaker 2: Turing prove that no algorithm can ever reliably answer that
- 24:52Speaker 2: question for all possible inputs. No matter how much time, memory,
- 24:57Speaker 2: or processing power you give the computer, it hits an
- 24:59Speaker 2: un unbreakable mathematical wall. It is logically forbidden from finding
- 25:04Speaker 2: the answer.
- 25:04Speaker 1: So the ultimate engine of the modern world, the algorithmic
- 25:07Speaker 1: recipe that runs everything from our bank accounts to our
- 25:09Speaker 1: space stations, has boundaries it can never cross.
- 25:13Speaker 2: Never.
- 25:13Speaker 1: I want you to mul that over. If the purest
- 25:15Speaker 1: form of logic we have the algorithm is mathematically barred
- 25:18Speaker 1: from understanding certain problems. What does that mean for the
- 25:21Speaker 1: ultimate limits of artificial intelligence? Will AI always have a
- 25:26Speaker 1: blind spot?
- 25:27Speaker 2: It's a fascinating question.
- 25:28Speaker 1: So the next time you hear someone blame the algorithm
- 25:31Speaker 1: for their social media feed, or you catch yourself thinking
- 25:33Speaker 1: of it as some mysterious omnipotent robot in the cloud,
- 25:37Speaker 1: remember what it really is. It's just a recipe, a
- 25:39Speaker 1: beautifully unforgiving, incredibly precise recipe, constantly making agonizing choices about time, space,
- 25:46Speaker 1: and data. And just like any recipe, its true power
- 25:49Speaker 1: and its ultimate limitations come entirely from the mind of
- 25:51Speaker 1: the human who wrote it. Until next time, keep diving deep.