WEBVTT

1
00:00:00.160 --> 00:00:02.799
<v Speaker 1>So back in nineteen sixty two, there was this math

2
00:00:02.879 --> 00:00:06.280
<v Speaker 1>picition named car Whore and he wrote like, just a

3
00:00:06.280 --> 00:00:07.759
<v Speaker 1>few lines of code to sort.

4
00:00:07.599 --> 00:00:10.119
<v Speaker 2>Data, right, a very early algorithm.

5
00:00:09.720 --> 00:00:14.240
<v Speaker 1>Yeah, exactly, And decades later, using pure mathematics, scientists predicted

6
00:00:14.240 --> 00:00:17.519
<v Speaker 1>that sorting exactly ten thousand items with that specific code

7
00:00:17.640 --> 00:00:21.120
<v Speaker 1>would take one hundred and seventy five, seven hundred and

8
00:00:21.199 --> 00:00:23.239
<v Speaker 1>forty six comparisons.

9
00:00:22.839 --> 00:00:24.760
<v Speaker 2>A very very specific number, I.

10
00:00:24.679 --> 00:00:27.679
<v Speaker 1>Mean, ridiculously specific. But here's the crazy part. When they

11
00:00:27.679 --> 00:00:30.039
<v Speaker 1>actually ran it on a physical machine, it took one

12
00:00:30.120 --> 00:00:33.039
<v Speaker 1>hundred and seventy six thousand, three hundred and fifty four comparisons.

13
00:00:33.079 --> 00:00:35.200
<v Speaker 2>Wow, so they were off by what a fraction of

14
00:00:35.200 --> 00:00:35.640
<v Speaker 2>a percent?

15
00:00:35.759 --> 00:00:39.479
<v Speaker 1>Basically. Yeah, the math predicted the totally chaotic, real world

16
00:00:39.520 --> 00:00:43.520
<v Speaker 1>execution of a computer program almost perfectly. So for today's

17
00:00:43.520 --> 00:00:46.079
<v Speaker 1>deep dive, we are unpacking the book that makes that

18
00:00:46.200 --> 00:00:48.079
<v Speaker 1>kind of mind blowing precision possible.

19
00:00:48.240 --> 00:00:51.000
<v Speaker 2>Yeah, we are looking at an Introduction to the Analysis

20
00:00:51.000 --> 00:00:55.399
<v Speaker 2>of Algorithms by Robert Sedgwick and Philippe Flagelay. And it's

21
00:00:55.439 --> 00:00:58.280
<v Speaker 2>a text that fundamentally redefines how we view the software

22
00:00:58.320 --> 00:00:59.759
<v Speaker 2>that literally runs our world.

23
00:01:00.039 --> 00:01:00.600
<v Speaker 1>It really does.

24
00:01:00.880 --> 00:01:04.439
<v Speaker 2>It shows how mathematicians can take just raw lines of

25
00:01:04.480 --> 00:01:08.920
<v Speaker 2>code and turn them into these incredibly elegant, predictable formulas,

26
00:01:08.920 --> 00:01:11.319
<v Speaker 2>formulas that save us a massive amount of computing time.

27
00:01:11.760 --> 00:01:14.239
<v Speaker 1>And there's like a very specific joy in doing this

28
00:01:14.319 --> 00:01:14.680
<v Speaker 1>kind of work.

29
00:01:14.760 --> 00:01:14.879
<v Speaker 2>Right.

30
00:01:15.239 --> 00:01:17.319
<v Speaker 1>In the forward to the book The Computer Science Legend,

31
00:01:17.359 --> 00:01:21.280
<v Speaker 1>Donald Nuth says, people who analyze algorithms get to experience

32
00:01:21.319 --> 00:01:23.280
<v Speaker 1>this double happiness.

33
00:01:23.319 --> 00:01:25.480
<v Speaker 2>Double happiness. I love that phrase. Right.

34
00:01:25.519 --> 00:01:28.480
<v Speaker 1>You get the sheer aesthetic beauty of just discovering these

35
00:01:28.519 --> 00:01:31.680
<v Speaker 1>hidden mathematical patterns, but then you also get the practical

36
00:01:31.719 --> 00:01:35.159
<v Speaker 1>payoff of well making real systems run faster.

37
00:01:35.439 --> 00:01:39.239
<v Speaker 2>It really bridges the gap, I mean between pure abstract

38
00:01:39.359 --> 00:01:42.760
<v Speaker 2>mathematics and the tangible engineering that you and I rely

39
00:01:42.879 --> 00:01:44.079
<v Speaker 2>on every single day.

40
00:01:44.159 --> 00:01:44.920
<v Speaker 1>Yeah, exactly.

41
00:01:45.000 --> 00:01:49.840
<v Speaker 2>These models essentially create like artificial universes, universes where logic

42
00:01:49.879 --> 00:01:52.680
<v Speaker 2>applies with absolute precision, so we can literally see the

43
00:01:52.680 --> 00:01:55.159
<v Speaker 2>future of a program before a single piece of data

44
00:01:55.200 --> 00:01:56.200
<v Speaker 2>is even processed.

45
00:01:56.400 --> 00:01:58.680
<v Speaker 1>But getting to that level of precision, right, I mean,

46
00:01:58.680 --> 00:02:02.040
<v Speaker 1>that wasn't just an overnight thing. It took decades. Yeah,

47
00:02:02.079 --> 00:02:03.480
<v Speaker 1>a really intense collaboration.

48
00:02:03.560 --> 00:02:06.000
<v Speaker 2>Absolutely, it was a massive human effort, and there's.

49
00:02:05.840 --> 00:02:09.800
<v Speaker 1>A really touching human element to this source material. Felipe

50
00:02:09.800 --> 00:02:14.039
<v Speaker 1>Flagelet passed away unexpectedly in Tenny eleven, and in the dedication,

51
00:02:14.479 --> 00:02:18.199
<v Speaker 1>Robert Sedgwick paints this really vivid picture of how their

52
00:02:18.199 --> 00:02:19.360
<v Speaker 1>life's work came together.

53
00:02:19.520 --> 00:02:23.479
<v Speaker 2>Right, It wasn't just them sitting in some sterile, isolated computer.

54
00:02:23.199 --> 00:02:26.759
<v Speaker 1>Lab, No, not at all. It was forged in Parisian cafes.

55
00:02:27.240 --> 00:02:29.719
<v Speaker 1>Sedgwick describes how they would, you know, share a puff

56
00:02:29.759 --> 00:02:32.159
<v Speaker 1>of smoke, a sip of beer, maybe a few bites

57
00:02:32.199 --> 00:02:32.919
<v Speaker 1>of steak frights.

58
00:02:33.000 --> 00:02:35.000
<v Speaker 2>Sounds like a great way to work, honestly.

59
00:02:34.800 --> 00:02:37.919
<v Speaker 1>I mean, sign me up. But they'd be laughing, having

60
00:02:37.960 --> 00:02:40.000
<v Speaker 1>a great time, and then they would just casually proceed

61
00:02:40.039 --> 00:02:43.680
<v Speaker 1>to map out incredibly complex theorems on cafe napkins.

62
00:02:43.840 --> 00:02:47.599
<v Speaker 2>It's just a vital reminder, you know, these imposing abstract concepts,

63
00:02:47.680 --> 00:02:52.319
<v Speaker 2>they're rooted in genuine human curiosity and deep friendship too.

64
00:02:52.800 --> 00:02:55.639
<v Speaker 2>The math that routes our global Internet traffic today was

65
00:02:55.759 --> 00:02:58.800
<v Speaker 2>literally hammered out over coffee and conversation.

66
00:02:59.240 --> 00:03:02.199
<v Speaker 1>So how did the cafe conversations actually help our phones

67
00:03:02.199 --> 00:03:04.960
<v Speaker 1>and computers run faster? I mean to understand that we

68
00:03:05.039 --> 00:03:07.039
<v Speaker 1>kind of have to look at why we analyze algorithms

69
00:03:07.080 --> 00:03:08.080
<v Speaker 1>in the first place.

70
00:03:08.240 --> 00:03:11.240
<v Speaker 2>Right, The overarching goal really is to evaluate if a

71
00:03:11.240 --> 00:03:15.159
<v Speaker 2>piece of code is actually suitable for a specific real

72
00:03:15.199 --> 00:03:16.639
<v Speaker 2>world application.

73
00:03:16.439 --> 00:03:18.400
<v Speaker 1>Like predicting how much time it will take or how

74
00:03:18.479 --> 00:03:19.080
<v Speaker 1>much memory is.

75
00:03:19.080 --> 00:03:21.400
<v Speaker 2>Going to eat up exactly, or you know, if you

76
00:03:21.439 --> 00:03:24.199
<v Speaker 2>are building an app for a mobile device, figuring out

77
00:03:24.240 --> 00:03:26.719
<v Speaker 2>how rapidly it's going to drain the battery.

78
00:03:26.639 --> 00:03:30.800
<v Speaker 1>And the source material highlights two very distinct approaches to

79
00:03:30.840 --> 00:03:31.759
<v Speaker 1>answering those questions.

80
00:03:31.879 --> 00:03:33.360
<v Speaker 2>Yeah, there's a big divide there.

81
00:03:33.560 --> 00:03:36.400
<v Speaker 1>The first is what they call the standard theory of algorithms,

82
00:03:36.439 --> 00:03:38.520
<v Speaker 1>which uses this thing called big O notation.

83
00:03:39.000 --> 00:03:42.360
<v Speaker 2>Right, big oh, anyone who has taken a computer science

84
00:03:42.360 --> 00:03:44.919
<v Speaker 2>class is probably groaning right now totally.

85
00:03:45.280 --> 00:03:49.120
<v Speaker 1>But this approach is basically primarily concerned with the absolute

86
00:03:49.159 --> 00:03:52.520
<v Speaker 1>worst case scenario, and to simplify the math, big O

87
00:03:52.719 --> 00:03:56.840
<v Speaker 1>intentionally hides all the constant factors and lower order terms.

88
00:03:56.919 --> 00:04:00.319
<v Speaker 2>It just tells you how an algorithm scales in broad strokes. Right.

89
00:04:00.639 --> 00:04:02.919
<v Speaker 1>But then you have the scientific approach, which is what

90
00:04:03.120 --> 00:04:05.000
<v Speaker 1>Sedgwick and flageolet really champion.

91
00:04:05.319 --> 00:04:08.240
<v Speaker 2>And this is where it gets interesting because instead of

92
00:04:08.240 --> 00:04:12.240
<v Speaker 2>sweeping those constants under the rug, this approach builds exact

93
00:04:12.360 --> 00:04:13.439
<v Speaker 2>mathematical models.

94
00:04:13.639 --> 00:04:17.800
<v Speaker 1>It's predicting the precise average case performance. We are talking

95
00:04:17.800 --> 00:04:22.000
<v Speaker 1>about mapping execution times down to the real seconds on

96
00:04:22.399 --> 00:04:24.160
<v Speaker 1>actual physical hardware.

97
00:04:24.279 --> 00:04:28.000
<v Speaker 2>Yeah, and that contrast fundamentally changes how you design a system.

98
00:04:28.079 --> 00:04:33.439
<v Speaker 2>I mean, theory classifies algorithms into these broad buckets of efficiency,

99
00:04:33.959 --> 00:04:37.079
<v Speaker 2>but science tells you exactly how they'll behave in your

100
00:04:37.079 --> 00:04:38.199
<v Speaker 2>specific environment.

101
00:04:38.600 --> 00:04:40.040
<v Speaker 1>I always kind of think about it like planning a

102
00:04:40.120 --> 00:04:40.560
<v Speaker 1>road trip.

103
00:04:40.680 --> 00:04:41.879
<v Speaker 2>Oh okay, let's hear it.

104
00:04:41.959 --> 00:04:44.199
<v Speaker 1>So the big O theoretical approach is like making a

105
00:04:44.279 --> 00:04:47.279
<v Speaker 1>rough estimate. You just say, driving across the country, Well,

106
00:04:47.319 --> 00:04:48.319
<v Speaker 1>it'll take a few days, right.

107
00:04:48.319 --> 00:04:50.720
<v Speaker 2>It gives you the absolute upper bound exactly.

108
00:04:50.879 --> 00:04:53.879
<v Speaker 1>But the scientific approach, that's like pulling up Google Maps.

109
00:04:54.199 --> 00:04:57.160
<v Speaker 1>It gives you the exact minute of your rival, factoring

110
00:04:57.199 --> 00:05:00.800
<v Speaker 1>in like average traffic speeds and how many stoplights there.

111
00:05:00.360 --> 00:05:03.439
<v Speaker 2>And knowing that exact minute changes everything about how you

112
00:05:03.480 --> 00:05:04.639
<v Speaker 2>plan the rest of your trip.

113
00:05:04.879 --> 00:05:07.439
<v Speaker 1>But let me push back on that a bit. If

114
00:05:07.560 --> 00:05:11.079
<v Speaker 1>modern computer's process, i mean literally billions of operations every

115
00:05:11.079 --> 00:05:15.959
<v Speaker 1>single second, is getting the exact minute of execution really necessary?

116
00:05:16.639 --> 00:05:20.720
<v Speaker 1>Doesn't the rough big O theoretical bound work just fine

117
00:05:20.759 --> 00:05:22.160
<v Speaker 1>for most modern stuff.

118
00:05:22.240 --> 00:05:25.160
<v Speaker 2>Well, at a small scale maybe sure, But at the

119
00:05:25.160 --> 00:05:28.439
<v Speaker 2>scale of a global database or a massive routing network,

120
00:05:28.720 --> 00:05:32.439
<v Speaker 2>those hidden constants in BIGO they dictate whether the system

121
00:05:32.480 --> 00:05:34.639
<v Speaker 2>is viable or whether it completely crashes.

122
00:05:34.759 --> 00:05:35.920
<v Speaker 1>Oh really, just the constants.

123
00:05:36.000 --> 00:05:38.360
<v Speaker 2>Yeah. Sorting data is actually the perfect example of this.

124
00:05:38.680 --> 00:05:42.439
<v Speaker 2>So theoretical analysis uses BIGO to prove that an algorithm

125
00:05:42.519 --> 00:05:45.120
<v Speaker 2>called merges sort is mathematically.

126
00:05:44.480 --> 00:05:46.600
<v Speaker 1>Optimal, meaning it's the best possible option.

127
00:05:46.839 --> 00:05:50.279
<v Speaker 2>Right. It hits the absolute theoretical lower bound for efficiency.

128
00:05:50.639 --> 00:05:53.600
<v Speaker 2>So in the big O universe you fundamentally cannot sort

129
00:05:53.639 --> 00:05:55.120
<v Speaker 2>data faster than merge sort.

130
00:05:55.279 --> 00:05:58.560
<v Speaker 1>Okay, so then every major software system in the world

131
00:05:58.600 --> 00:05:59.680
<v Speaker 1>should just be using murger.

132
00:05:59.519 --> 00:06:02.519
<v Speaker 2>Sort, right thinks. So, yet in practice, a totally different

133
00:06:02.519 --> 00:06:04.959
<v Speaker 2>algorithm called quicksword is vastly more popular.

134
00:06:05.040 --> 00:06:08.040
<v Speaker 1>Wait, why if mergent sort is the theoretical winner.

135
00:06:07.800 --> 00:06:12.120
<v Speaker 2>Because big ooation drops the constant factors, it completely ignores

136
00:06:12.160 --> 00:06:15.720
<v Speaker 2>the actual physical cost of the operations happening inside the

137
00:06:15.759 --> 00:06:16.959
<v Speaker 2>code's innermost loops.

138
00:06:17.160 --> 00:06:18.800
<v Speaker 1>Oh I see, merger.

139
00:06:18.519 --> 00:06:21.959
<v Speaker 2>Sort requires allocating all these extra memory arrays to move

140
00:06:22.000 --> 00:06:26.560
<v Speaker 2>the data around, and memory allocation is computationally expensive. Quicksort,

141
00:06:26.600 --> 00:06:30.279
<v Speaker 2>on the other hand, simply increment's pointers and swaps items

142
00:06:30.279 --> 00:06:31.160
<v Speaker 2>in place, so.

143
00:06:31.160 --> 00:06:33.839
<v Speaker 1>Quicksort has a much lower cost. It cost per.

144
00:06:33.680 --> 00:06:37.480
<v Speaker 2>Operation massively lower. So the theory identifies merger sort as

145
00:06:37.519 --> 00:06:41.600
<v Speaker 2>having the optimal scaling curve, But scientific analysis looks at

146
00:06:41.639 --> 00:06:45.560
<v Speaker 2>the actual hardware costs and says, hey, quicksword's hidden details

147
00:06:45.560 --> 00:06:46.800
<v Speaker 2>work heavily in its favor.

148
00:06:46.920 --> 00:06:50.160
<v Speaker 1>Theory identifies the good algorithms, but science tells us which

149
00:06:50.199 --> 00:06:52.639
<v Speaker 1>one actually wins the race when the rubber meets.

150
00:06:52.439 --> 00:06:55.439
<v Speaker 2>The road exactly, science wins the game on actual hardware.

151
00:06:55.720 --> 00:06:59.040
<v Speaker 1>But wait, getting an exact scientific prediction like that requires

152
00:06:59.040 --> 00:07:01.639
<v Speaker 1>knowing what kind of data is. The algorithm's got a process, right, Yeah,

153
00:07:01.639 --> 00:07:03.600
<v Speaker 1>you need a model, and real world data is just

154
00:07:03.759 --> 00:07:07.079
<v Speaker 1>chaotic and messy. So how do you mathematically model chaos

155
00:07:07.839 --> 00:07:09.120
<v Speaker 1>to get an accurate prediction?

156
00:07:09.560 --> 00:07:12.360
<v Speaker 2>Well, you have to rely on what's called average case analysis.

157
00:07:12.839 --> 00:07:16.079
<v Speaker 2>To predict typical performance. You essentially have to assume the

158
00:07:16.079 --> 00:07:18.600
<v Speaker 2>input data follows a strict random model.

159
00:07:19.199 --> 00:07:22.720
<v Speaker 1>And what's deeply counterintuitive about that to me is that

160
00:07:22.800 --> 00:07:27.240
<v Speaker 1>simple models of randomness are actually astonishingly accurate for mapping

161
00:07:27.399 --> 00:07:28.720
<v Speaker 1>real human behavior.

162
00:07:28.920 --> 00:07:30.120
<v Speaker 2>It's true, they really are.

163
00:07:30.240 --> 00:07:32.519
<v Speaker 1>I mean, it genuinely doesn't matter if you're sorting bank

164
00:07:32.519 --> 00:07:35.879
<v Speaker 1>account numbers, or routing Internet traffic, or trying to crack

165
00:07:35.920 --> 00:07:41.560
<v Speaker 1>cryptographic keys. The data streams humans generate act, mathematically speaking,

166
00:07:41.920 --> 00:07:43.600
<v Speaker 1>as though they are completely random.

167
00:07:44.240 --> 00:07:47.279
<v Speaker 2>Yeah, it's just that the sheer volume of data smooths

168
00:07:47.319 --> 00:07:51.199
<v Speaker 2>out all the individual human biases. The textbook even notes

169
00:07:51.240 --> 00:07:54.399
<v Speaker 2>this incredible phenomenon in computational biology.

170
00:07:54.560 --> 00:07:56.120
<v Speaker 1>Oh, right, with the DNA sequences.

171
00:07:56.240 --> 00:07:59.519
<v Speaker 2>Exactly, if scientists map a DNA sequence and find that

172
00:07:59.519 --> 00:08:02.439
<v Speaker 2>their data and it significantly deviates from a random model,

173
00:08:02.560 --> 00:08:04.600
<v Speaker 2>they don't think their mathematical model is broken.

174
00:08:04.680 --> 00:08:06.079
<v Speaker 1>They realized they found something real.

175
00:08:06.279 --> 00:08:11.040
<v Speaker 2>Yes, it usually means they've discovered a fundamental, structured biological process.

176
00:08:11.720 --> 00:08:15.560
<v Speaker 2>The deviation from randomness is the actual scientific signal.

177
00:08:15.519 --> 00:08:20.079
<v Speaker 1>That is fascinating. But what if what if someone is

178
00:08:20.199 --> 00:08:21.920
<v Speaker 1>intentionally trying to break things?

179
00:08:22.120 --> 00:08:23.480
<v Speaker 2>You mean, like a malicious actor.

180
00:08:23.800 --> 00:08:27.360
<v Speaker 1>Yeah, say you're building a server and someone purposefully sends

181
00:08:27.600 --> 00:08:31.920
<v Speaker 1>perfectly reversed data sets designed to trigger the absolute worst

182
00:08:31.920 --> 00:08:35.960
<v Speaker 1>case execution time and just crash your system. Doesn't the

183
00:08:35.960 --> 00:08:39.240
<v Speaker 1>whole average case prediction just fall apart immediately.

184
00:08:38.879 --> 00:08:42.399
<v Speaker 2>It would, which brings us to this brilliant workaround discussed

185
00:08:42.399 --> 00:08:45.000
<v Speaker 2>in the text randomized algorithms.

186
00:08:45.039 --> 00:08:46.039
<v Speaker 1>Okay, how does that work?

187
00:08:46.120 --> 00:08:49.720
<v Speaker 2>Basically, if you cannot trust the incoming data to be random,

188
00:08:50.120 --> 00:08:52.559
<v Speaker 2>you just forcefully inject the randomness yourself.

189
00:08:52.720 --> 00:08:55.840
<v Speaker 1>You essentially scramble the data before the algorithm even touches it.

190
00:08:55.919 --> 00:08:59.480
<v Speaker 2>Exactly, you take control of the chaos. You can randomly

191
00:08:59.519 --> 00:09:01.799
<v Speaker 2>shuffle the and put a ray before you start. Or,

192
00:09:02.120 --> 00:09:04.240
<v Speaker 2>in the case of quick sort, which works by picking

193
00:09:04.279 --> 00:09:07.039
<v Speaker 2>a pivot element and organizing data around it, you don't

194
00:09:07.039 --> 00:09:07.960
<v Speaker 2>just pick the first item.

195
00:09:08.080 --> 00:09:10.159
<v Speaker 1>You use a random number generator to pick.

196
00:09:10.000 --> 00:09:14.240
<v Speaker 2>The pivot right. By artificially injecting randomness into the core

197
00:09:14.360 --> 00:09:18.600
<v Speaker 2>mechanism of the algorithm itself, you mathematically inoculate it against

198
00:09:18.679 --> 00:09:19.720
<v Speaker 2>malicious data.

199
00:09:19.840 --> 00:09:23.440
<v Speaker 1>So it's physically impossible for a bad actor to force

200
00:09:23.480 --> 00:09:24.200
<v Speaker 1>a worst.

201
00:09:23.960 --> 00:09:27.840
<v Speaker 2>Case scenario exactly because the algorithm's path is being decided

202
00:09:27.840 --> 00:09:31.399
<v Speaker 2>by random chance at runtime that guarantees it will perform

203
00:09:31.440 --> 00:09:33.399
<v Speaker 2>at its predicted average case speed.

204
00:09:33.960 --> 00:09:37.320
<v Speaker 1>That's just an incredibly elegant defense mechanism. I love that.

205
00:09:37.759 --> 00:09:39.960
<v Speaker 1>Let's look a little closer at quicksort, actually, since it

206
00:09:40.000 --> 00:09:42.919
<v Speaker 1>really is the poster child for this kind of precise

207
00:09:43.200 --> 00:09:44.159
<v Speaker 1>scientific modeling.

208
00:09:44.360 --> 00:09:47.360
<v Speaker 2>Yeah, car Horror invented it in nineteen sixty two, as

209
00:09:47.360 --> 00:09:48.240
<v Speaker 2>we mentioned.

210
00:09:47.919 --> 00:09:50.720
<v Speaker 1>And it relies on this divide and conquer methodology. Right.

211
00:09:51.159 --> 00:09:54.320
<v Speaker 1>It takes a massive file, breaks it into pieces, and

212
00:09:54.360 --> 00:09:58.360
<v Speaker 1>then recursively sorts smaller and smaller subfiles until everything is

213
00:09:58.440 --> 00:09:59.480
<v Speaker 1>perfectly in order.

214
00:10:00.159 --> 00:10:03.440
<v Speaker 2>Right. And in mathematics, that kind of recursive loop translates

215
00:10:03.440 --> 00:10:06.840
<v Speaker 2>into what we call recurrence relations. Recurrence relations, Yeah, it's

216
00:10:06.840 --> 00:10:09.159
<v Speaker 2>an equation that defines a sequence based on its own

217
00:10:09.240 --> 00:10:12.840
<v Speaker 2>previous terms. Because quicksort calls itself over and over on

218
00:10:12.960 --> 00:10:16.639
<v Speaker 2>smaller chunks of data, the math perfectly mirrors the architecture

219
00:10:16.639 --> 00:10:17.600
<v Speaker 2>of the code.

220
00:10:17.399 --> 00:10:21.360
<v Speaker 1>And the textbook actually outlines the recurrence relation for quicksort.

221
00:10:21.600 --> 00:10:24.480
<v Speaker 1>It proves mathematically that it takes about two times n

222
00:10:25.120 --> 00:10:29.360
<v Speaker 1>times the natural log of en comparisons to sort en items.

223
00:10:28.960 --> 00:10:31.399
<v Speaker 2>Which brings us back to that stunning table of proof

224
00:10:31.600 --> 00:10:32.679
<v Speaker 2>from the intro right.

225
00:10:33.159 --> 00:10:36.600
<v Speaker 1>Using nothing but that pure mathematical formula, they predicted a

226
00:10:36.600 --> 00:10:39.440
<v Speaker 1>ten thousand item file would need one hundred and seventy

227
00:10:39.440 --> 00:10:42.879
<v Speaker 1>five thousand, seven hundred and forty six comparisons, and the

228
00:10:42.919 --> 00:10:46.440
<v Speaker 1>actual physical code executed it in one hundred and seventy

229
00:10:46.480 --> 00:10:48.200
<v Speaker 1>six thousand, three hundred and fifty.

230
00:10:47.919 --> 00:10:50.759
<v Speaker 2>Four, being off by a fraction of a percent. Like that,

231
00:10:50.799 --> 00:10:55.159
<v Speaker 2>I mean, it completely validates the entire discipline of algorithm analysis.

232
00:10:55.519 --> 00:10:58.480
<v Speaker 2>We can know precisely how our machines will behave, literally

233
00:10:58.519 --> 00:10:59.639
<v Speaker 2>down to the microsecond.

234
00:10:59.799 --> 00:11:03.000
<v Speaker 1>The textbook also details a very specific practical tweak to

235
00:11:03.039 --> 00:11:05.720
<v Speaker 1>quick sort that takes advantage of all this precision.

236
00:11:05.840 --> 00:11:07.919
<v Speaker 2>Oh the cutoff point. Yeah, this is great.

237
00:11:07.960 --> 00:11:11.240
<v Speaker 1>Because quick sort relies on constantly dividing lists into smaller

238
00:11:11.279 --> 00:11:14.039
<v Speaker 1>chunks and calling itself recursively, it carries a ton of

239
00:11:14.080 --> 00:11:15.039
<v Speaker 1>structural overhead.

240
00:11:15.120 --> 00:11:17.559
<v Speaker 2>Yeah, it's actually terribly inefficient for tiny lists.

241
00:11:17.639 --> 00:11:20.200
<v Speaker 1>I was compared to like firing up a massive, fully

242
00:11:20.200 --> 00:11:23.320
<v Speaker 1>automated automotive assembly line just to make a single ham sandwich.

243
00:11:23.360 --> 00:11:24.639
<v Speaker 2>That is a perfect analogy.

244
00:11:24.840 --> 00:11:28.519
<v Speaker 1>The overhead of turning the factory on vastly outweighs the

245
00:11:28.559 --> 00:11:30.200
<v Speaker 1>work being done to make the sandwich.

246
00:11:30.559 --> 00:11:33.000
<v Speaker 2>Right, And the text demonstrates that if you stop quick

247
00:11:33.080 --> 00:11:35.840
<v Speaker 2>sort when the sub files get small enough and just

248
00:11:35.840 --> 00:11:39.039
<v Speaker 2>switch to a highly simplistic method called insertion sort, you

249
00:11:39.120 --> 00:11:40.480
<v Speaker 2>save a massive amount of time.

250
00:11:40.720 --> 00:11:43.559
<v Speaker 1>Insertion sort is the one that's terrible for large data sets.

251
00:11:43.399 --> 00:11:46.279
<v Speaker 2>Right, horrible for large data sets, But for a tiny

252
00:11:46.320 --> 00:11:49.320
<v Speaker 2>list it has almost zero overhead. It just looks at

253
00:11:49.320 --> 00:11:51.759
<v Speaker 2>the few items and shifts them into place locally.

254
00:11:51.840 --> 00:11:55.080
<v Speaker 1>And because we have these incredibly precise mathematical formulas, we

255
00:11:55.120 --> 00:11:56.879
<v Speaker 1>don't even have to guess when to shut down the

256
00:11:56.919 --> 00:11:58.720
<v Speaker 1>factory assembly line exactly.

257
00:11:59.039 --> 00:12:02.440
<v Speaker 2>The math explicit calculates that the optimal cutoff point is

258
00:12:02.440 --> 00:12:05.159
<v Speaker 2>a file size of roughly ten to twenty items.

259
00:12:05.399 --> 00:12:07.840
<v Speaker 1>So you run quicksort to slice the massive data set

260
00:12:07.879 --> 00:12:11.480
<v Speaker 1>down into chunks of say fifteen, and then let insertion

261
00:12:11.600 --> 00:12:13.559
<v Speaker 1>sort quickly sweep through and finish it off.

262
00:12:14.039 --> 00:12:16.360
<v Speaker 2>We don't have to rely on intuition or trial and

263
00:12:16.480 --> 00:12:20.360
<v Speaker 2>error anymore. The scientific approach gives us the exact threshold

264
00:12:20.399 --> 00:12:22.080
<v Speaker 2>for maximum hardware efficiency.

265
00:12:22.440 --> 00:12:27.159
<v Speaker 1>That is so satisfying. But quicksort relies on that randomized pivot,

266
00:12:27.600 --> 00:12:30.679
<v Speaker 1>meaning it rarely divides its sub files perfectly in half.

267
00:12:31.480 --> 00:12:35.919
<v Speaker 1>What about dividing conquer algorithms that literally mandate a perfect

268
00:12:35.919 --> 00:12:40.039
<v Speaker 1>fifty to fifty split, like merge sort or binary search.

269
00:12:40.200 --> 00:12:44.279
<v Speaker 2>Ah yeah, forcing a perfect fifty to fifty split actually

270
00:12:44.279 --> 00:12:48.440
<v Speaker 2>introduces this profound mathematical glitch into the system.

271
00:12:48.559 --> 00:12:50.759
<v Speaker 1>A glitch how so, well, think about it.

272
00:12:51.039 --> 00:12:54.639
<v Speaker 2>You cannot cleanly have an odd number of discrete items.

273
00:12:54.639 --> 00:12:56.960
<v Speaker 1>Oh, right, You can't have half a data package.

274
00:12:56.600 --> 00:12:59.919
<v Speaker 2>Exactly, so you are continually forcing an asymmetrical split. You

275
00:13:00.120 --> 00:13:02.279
<v Speaker 2>have seven items, you have to divide them into chunks of.

276
00:13:02.279 --> 00:13:05.080
<v Speaker 1>Three and four, which seems totally trivial if you're just

277
00:13:05.120 --> 00:13:07.360
<v Speaker 1>looking at seven items. But I guess when you recurse

278
00:13:07.399 --> 00:13:10.360
<v Speaker 1>that imbalance thousands of times down a massive binary tree,

279
00:13:10.720 --> 00:13:13.840
<v Speaker 1>those tiny fractional differences start to violently compound.

280
00:13:13.919 --> 00:13:16.720
<v Speaker 2>They really do. And the visual graphs of this phenomenon

281
00:13:16.799 --> 00:13:18.960
<v Speaker 2>in the textbook are just absolutely striking.

282
00:13:19.080 --> 00:13:21.159
<v Speaker 1>I was looking at those at a high level. The

283
00:13:21.200 --> 00:13:24.519
<v Speaker 1>performance looks like this smooth, predictable logarithmic curve.

284
00:13:24.679 --> 00:13:26.639
<v Speaker 2>But then you zoom in on the data points.

285
00:13:26.960 --> 00:13:31.480
<v Speaker 1>Yes, when you zoom in, the smooth curve completely shatters.

286
00:13:32.000 --> 00:13:36.440
<v Speaker 1>It reveals these deeply jagged, fractal like periodic ways. The

287
00:13:36.440 --> 00:13:39.360
<v Speaker 1>speed of the algorithm violently fluctuates just depending on the

288
00:13:39.399 --> 00:13:40.879
<v Speaker 1>exact input size.

289
00:13:40.559 --> 00:13:44.039
<v Speaker 2>And those jagged discontinuities they aren't just random noise or

290
00:13:44.039 --> 00:13:48.600
<v Speaker 2>processing errors. They map flawlessly to the deep architectural properties

291
00:13:48.639 --> 00:13:49.759
<v Speaker 2>of binary numbers.

292
00:13:49.840 --> 00:13:50.679
<v Speaker 1>Wait, what do you mean?

293
00:13:50.799 --> 00:13:53.519
<v Speaker 2>Okay, so if you analyze the worst case comparisons in

294
00:13:53.600 --> 00:13:57.639
<v Speaker 2>binary search, the exact number of operations perfectly mirrors the

295
00:13:57.720 --> 00:14:00.799
<v Speaker 2>number of bits required to represent the file side in binary.

296
00:14:01.000 --> 00:14:04.399
<v Speaker 1>Oh wow, So the algorithm doesn't know what binary is, obviously,

297
00:14:04.519 --> 00:14:06.600
<v Speaker 1>but just by dividing by two over and over again,

298
00:14:06.639 --> 00:14:10.159
<v Speaker 1>it inadvertently traces the entire underlying structure of the binary

299
00:14:10.200 --> 00:14:11.240
<v Speaker 1>number system itself.

300
00:14:11.360 --> 00:14:15.279
<v Speaker 2>Precisely, the periodic waves and the performance map directly correspond

301
00:14:15.320 --> 00:14:18.480
<v Speaker 2>to binary concepts like population counts, which is literally just

302
00:14:18.559 --> 00:14:20.639
<v Speaker 2>counting the number of one bits in a binary string,

303
00:14:20.759 --> 00:14:23.720
<v Speaker 2>or the ruler function, which maps the number of trailing zeros.

304
00:14:24.000 --> 00:14:27.200
<v Speaker 1>So the physical execution time of the code is permanently

305
00:14:27.240 --> 00:14:29.720
<v Speaker 1>shackled to the anatomy of base two mathematics.

306
00:14:30.080 --> 00:14:32.200
<v Speaker 2>Shackled is a good word for it. It's built right

307
00:14:32.240 --> 00:14:33.600
<v Speaker 2>into the fabric of the universe.

308
00:14:33.919 --> 00:14:37.440
<v Speaker 1>So if an algorithm's speed isn't just a smooth line,

309
00:14:37.679 --> 00:14:42.000
<v Speaker 1>but is actually this jagged fractal wave tied to binary properties,

310
00:14:42.440 --> 00:14:45.320
<v Speaker 1>I mean, you can't just use basic algebra to predict it, right.

311
00:14:45.600 --> 00:14:50.120
<v Speaker 1>You can't solve an infinite jagged recursive loop step by step.

312
00:14:50.240 --> 00:14:53.639
<v Speaker 2>You really can't. Mathematicians need a tool that can essentially

313
00:14:53.720 --> 00:14:56.639
<v Speaker 2>swallow that entire infinite sequence.

314
00:14:56.240 --> 00:14:58.840
<v Speaker 1>Hole, which brings us right back to Robert Sedgwick and

315
00:14:58.840 --> 00:15:02.559
<v Speaker 1>Felipe Flagela in the Parisian Cafes. To map out those

316
00:15:02.600 --> 00:15:08.000
<v Speaker 1>chaotic recurrences, they champion a master mathematical tool, right, generating function.

317
00:15:08.200 --> 00:15:09.519
<v Speaker 2>Yes, generating functions.

318
00:15:09.519 --> 00:15:12.840
<v Speaker 1>So a generating function basically takes an entire infinite sequence

319
00:15:13.279 --> 00:15:16.960
<v Speaker 1>of performance parameters and just encapsulates them into one single

320
00:15:17.000 --> 00:15:17.960
<v Speaker 1>mathematical object.

321
00:15:18.080 --> 00:15:20.679
<v Speaker 2>Right. Think of it as algebraic compression. It's like taking

322
00:15:20.759 --> 00:15:24.320
<v Speaker 2>an infinite sequence of numbers and attaching each individual number

323
00:15:24.360 --> 00:15:27.360
<v Speaker 2>to a progressively higher power of a variable like.

324
00:15:27.559 --> 00:15:29.159
<v Speaker 1>X okay, making it a polynomial.

325
00:15:29.320 --> 00:15:31.840
<v Speaker 2>Exactly, You string them all together, and you have just

326
00:15:32.000 --> 00:15:36.039
<v Speaker 2>packed an infinite sequence into a single massive polynomial equation.

327
00:15:36.440 --> 00:15:38.799
<v Speaker 1>I kind of think of it as a mathematical zip file.

328
00:15:38.919 --> 00:15:41.000
<v Speaker 2>Oh, a zip file. That's a great way to put it.

329
00:15:41.120 --> 00:15:45.279
<v Speaker 1>Yeah, Instead of dealing with an infinity of scattered individual

330
00:15:45.399 --> 00:15:47.919
<v Speaker 1>data points, you can press them all into one zip

331
00:15:48.120 --> 00:15:49.720
<v Speaker 1>file that you can easily maneuver.

332
00:15:49.879 --> 00:15:52.000
<v Speaker 2>And the true power of that zip file is that

333
00:15:52.039 --> 00:15:56.000
<v Speaker 2>you can actually perform calculus and algebra on the compressed.

334
00:15:55.559 --> 00:15:57.360
<v Speaker 1>File itself without unpacking it.

335
00:15:57.440 --> 00:16:01.679
<v Speaker 2>Without unpacking it, by multiplying these generating functions together or

336
00:16:01.759 --> 00:16:06.600
<v Speaker 2>taking their derivatives. You are simultaneously manipulating every single number

337
00:16:06.679 --> 00:16:10.960
<v Speaker 2>in the infinite sequence all at once. You totally bypass

338
00:16:11.120 --> 00:16:14.399
<v Speaker 2>the messy, jagged infinity of those recursive loops.

339
00:16:14.480 --> 00:16:17.600
<v Speaker 1>That is just brilliant. And the source material divides these

340
00:16:17.600 --> 00:16:21.840
<v Speaker 1>into two main categories, right, ordinary generating functions or OGFs

341
00:16:22.279 --> 00:16:24.639
<v Speaker 1>and exponential generating functions or EGFs.

342
00:16:24.879 --> 00:16:27.559
<v Speaker 2>Right, and it notes that egs are strictly necessary when

343
00:16:27.600 --> 00:16:30.120
<v Speaker 2>you are analyzing labeled items.

344
00:16:29.679 --> 00:16:33.039
<v Speaker 1>Label items being when the distinct identity of every single

345
00:16:33.080 --> 00:16:34.960
<v Speaker 1>item actually matters to.

346
00:16:34.919 --> 00:16:39.600
<v Speaker 2>The outcome exactly. And the mechanism behind an exponential generating

347
00:16:39.600 --> 00:16:42.159
<v Speaker 2>function is just brilliant. If you have a sequence of

348
00:16:42.200 --> 00:16:45.879
<v Speaker 2>distinct labeled items, the number of ways they can be

349
00:16:45.960 --> 00:16:48.759
<v Speaker 2>arranged explodes factorially.

350
00:16:48.240 --> 00:16:50.679
<v Speaker 1>Meaning the numbers get huge, very fast.

351
00:16:50.399 --> 00:16:53.200
<v Speaker 2>Insanely fast. I mean, five items can be arranged in

352
00:16:53.200 --> 00:16:56.639
<v Speaker 2>one hundred and twenty different ways, but ten items that's

353
00:16:56.679 --> 00:16:59.240
<v Speaker 2>over three point six million permutations.

354
00:16:59.320 --> 00:16:59.759
<v Speaker 1>Wow.

355
00:16:59.840 --> 00:17:02.399
<v Speaker 2>So if your algorithm's cost depends on the structure of

356
00:17:02.440 --> 00:17:05.279
<v Speaker 2>the data and not the specific labels, tracking all those

357
00:17:05.319 --> 00:17:09.440
<v Speaker 2>redundant permutations causes the math to instantly blow up to infinity.

358
00:17:09.519 --> 00:17:12.240
<v Speaker 1>So how does the EGF fix that explosion.

359
00:17:12.319 --> 00:17:15.279
<v Speaker 2>An exponential generating function divides the terms in the series

360
00:17:15.279 --> 00:17:18.920
<v Speaker 2>by a factorial. By dividing by the factorial, you mathematically

361
00:17:18.960 --> 00:17:22.000
<v Speaker 2>cancel out the noise of all those different redundant arrangements.

362
00:17:22.039 --> 00:17:23.720
<v Speaker 1>Oh that makes so much sense. It strips away all

363
00:17:23.759 --> 00:17:25.160
<v Speaker 1>those millions of permutation that.

364
00:17:25.200 --> 00:17:29.160
<v Speaker 2>Goes right, isolating just the core structural behavior of the algorithm,

365
00:17:29.200 --> 00:17:30.960
<v Speaker 2>so you can actually solve the equation.

366
00:17:31.160 --> 00:17:33.799
<v Speaker 1>You never actually have to unpack the infinite sequence until

367
00:17:33.839 --> 00:17:36.519
<v Speaker 1>the very end when you finally need the answer. It's

368
00:17:36.559 --> 00:17:38.880
<v Speaker 1>really the ultimate shortcut to the truth of how a

369
00:17:38.960 --> 00:17:39.839
<v Speaker 1>system operates.

370
00:17:40.160 --> 00:17:44.480
<v Speaker 2>It's undeniably complex, sure, but it represents this breathtaking journey

371
00:17:45.119 --> 00:17:47.799
<v Speaker 2>going from just a few lines of type code to

372
00:17:47.880 --> 00:17:50.920
<v Speaker 2>the fundamental, immutable truths of mathematics.

373
00:17:51.000 --> 00:17:53.640
<v Speaker 1>Bringing this all together, I mean, we started today exploring

374
00:17:53.680 --> 00:17:57.480
<v Speaker 1>the double happiness of theory and practice. How uncovering elegant

375
00:17:57.519 --> 00:18:00.559
<v Speaker 1>math results in real world software actually run faster.

376
00:18:00.720 --> 00:18:02.839
<v Speaker 2>Yeah, and we saw how the broad strokes of big

377
00:18:02.839 --> 00:18:07.559
<v Speaker 2>o' notation really pale in comparison to pinpoint scientific.

378
00:18:07.079 --> 00:18:10.880
<v Speaker 1>Modeling, revealing exactly why quicksword defeats merge sword on actual

379
00:18:10.920 --> 00:18:12.559
<v Speaker 1>hardware despite the theory.

380
00:18:12.720 --> 00:18:17.480
<v Speaker 2>Right, And we discovered how injecting artificial randomness inoculate systems

381
00:18:17.519 --> 00:18:20.839
<v Speaker 2>against malicious data, guaranteeing predictable performance.

382
00:18:20.920 --> 00:18:23.480
<v Speaker 1>We pulled apart the mechanics of divide and conquer recurrences too,

383
00:18:23.920 --> 00:18:27.279
<v Speaker 1>just watching as pure mathematics predicted computer execution times down

384
00:18:27.319 --> 00:18:28.759
<v Speaker 1>to a fraction of a percent.

385
00:18:28.519 --> 00:18:32.079
<v Speaker 2>And even dictated the exact threshold for switching sorting methods.

386
00:18:32.400 --> 00:18:36.240
<v Speaker 1>We explored the fractal heartbeat of binary algorithms, seeing how

387
00:18:36.240 --> 00:18:39.720
<v Speaker 1>dividing odd numbers creates these jagged waves that mirror the

388
00:18:39.759 --> 00:18:42.599
<v Speaker 1>anatomy of the base two system. And finally we saw

389
00:18:42.640 --> 00:18:47.200
<v Speaker 1>how Sedgewick and Flagelat utilized the algebraic compression of generating

390
00:18:47.240 --> 00:18:52.000
<v Speaker 1>functions to just zip all that infinite complexity into solvable equations.

391
00:18:52.279 --> 00:18:55.440
<v Speaker 2>It really shows us that beneath the totally chaotic surface

392
00:18:55.480 --> 00:19:00.160
<v Speaker 2>of our digital world, there is a rigid, beautiful mathematical order.

393
00:19:00.279 --> 00:19:02.079
<v Speaker 1>It really does me and I want to leave you

394
00:19:02.119 --> 00:19:05.519
<v Speaker 1>with one final kind of philosophical twist, drawn directly from

395
00:19:05.559 --> 00:19:07.400
<v Speaker 1>the text Musings on Randomness.

396
00:19:07.440 --> 00:19:08.200
<v Speaker 2>Okay, let's hear it.

397
00:19:08.440 --> 00:19:12.440
<v Speaker 1>The text quotes Albert Einstein's famous assertion God does not

398
00:19:12.440 --> 00:19:15.599
<v Speaker 1>play dice r. The core implication there is that true

399
00:19:15.680 --> 00:19:19.240
<v Speaker 1>randomness in nature is actually exceptionally rare. If we find

400
00:19:19.279 --> 00:19:23.000
<v Speaker 1>deviations from random models, we haven't failed. We've likely discovered

401
00:19:23.000 --> 00:19:26.400
<v Speaker 1>a fundamental natural truth, much like a hidden biological.

402
00:19:25.839 --> 00:19:28.599
<v Speaker 2>Process, a structural signal totally hidden in the noise.

403
00:19:29.039 --> 00:19:32.359
<v Speaker 1>Exactly, we have spent this whole deep dive looking at

404
00:19:32.400 --> 00:19:36.440
<v Speaker 1>how perfectly our random mathematical models can predict the behavior

405
00:19:36.519 --> 00:19:40.039
<v Speaker 1>of computer algorithms. But what happens when the tables turn

406
00:19:40.480 --> 00:19:42.240
<v Speaker 1>and those algorithms start modeling us?

407
00:19:42.440 --> 00:19:44.160
<v Speaker 2>Oh wow, that's a thought.

408
00:19:44.440 --> 00:19:47.240
<v Speaker 1>Think about the chaotic data of our daily lives. I mean,

409
00:19:47.279 --> 00:19:51.000
<v Speaker 1>our clicks, our views, our purchasing habits, our movements, our

410
00:19:51.079 --> 00:19:54.559
<v Speaker 1>human behaviors really just inputs waiting to be perfectly encapsulated

411
00:19:54.599 --> 00:19:58.680
<v Speaker 1>by some cosmic generating function. We the random data right?

412
00:19:58.920 --> 00:20:02.039
<v Speaker 1>Or is there a hidden, fractal heartbeat to human nature

413
00:20:02.119 --> 00:20:05.000
<v Speaker 1>that these algorithms are already tracing. It's definitely something to

414
00:20:05.079 --> 00:20:07.319
<v Speaker 1>mull over the next time you turn the key and

415
00:20:07.599 --> 00:20:11.319
<v Speaker 1>expect a straightforward execution. Thank you so much for taking

416
00:20:11.319 --> 00:20:13.240
<v Speaker 1>this deep dive with us today. Keep looking for the

417
00:20:13.279 --> 00:20:16.240
<v Speaker 1>elegant math hiding just beneath the surface of your daily life.
