Learn 10 essential math concepts for software engineering and technical interviews. Understand how programmers use mathematics in fields like AI, game dev, crypto, machine learning, and more.

#math #programming #top10

💬 Chat with Me on Discord

https://discord.gg/fireship

🔗 Resources

Computer Science 101 https://youtu.be/-uleG_Vecis
Cryptography for Developers https://youtu.be/NuyzuNBFWxQ
Technical Interview Prep https://youtu.be/1t1_a1BZ04o

📚 Chapters

🔥 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

- Do programmers need math?
- Math tutorial for programming
- Machine learning math
- Do computer hackers use math?
- Linear algebra for programmers
- Boolean Algebra explained
- Combinatorics explained
- How does Big-O notation work
2024-02-04T05:07:27.404Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
f595b138-8cee-4ed1-9269-0cc60e5d4a62
ed2a8d069dd37622aa2ec3ba3a20d33d2224724d3c29a83d59192edc83dc478d
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
People often say you don't need to know any math to program a computer, and that's truthy.
However, any sufficiently advanced technology is from magic, but magic isn't real.
Math explains it all.
Developers often avoid learning math because it looks scary, but it actually makes complicated magic like computer graphics and neural networks easier to understand.
And not just that, but it unlocks the secrets of the entire physical universe.
There's a few abstract math concepts for programmers that you just can't ignore, and understanding them will make you think more like a true engineer.
I'm no math genius.
In fact, I'm the opposite, which makes me uniquely qualified to teach 10 essential math concepts using memes and other visual aids that almost anybody can understand.
The first person who survives until the end cracks the code will win this one of a kind Balenciaga Fireship Hoodie.
Let's jump right into topic number 1, Boolean algebra, which is used almost every time you write code.
A boolean is a binary variable that can have two possible values, true or false.
Now there are 3 operators that you can use to work with them, and, or, and not, or conjunction, disjunction, and negation if you wanna be fancy.
Imagine you're trying to get a girlfriend.
We can use the boolean variables of rich and handsome to describe you.
If you're both rich and handsome, you'll definitely get a girlfriend.
But if you're not rich and not handsome, you'll have to pay for an OnlyFans girlfriend.
If you're rich or handsome, you can still get a girlfriend, but your selection is more limited.
We can represent this logic in code with things like if statements, but we can also do it with Venn diagrams like you've been doing since grade school.
And you can also create truth tables like this one here, which comes in handy in zombie apocalypse type situations.
But that brings us to concept 2, numeral systems like base 2.
Throughout history, humans have come up with all kinds of clever ways to count things, but almost all of them use base 10 like the 10 fingers on your hands.
Distance.
Like in the number 423, the 4 is in the 100s place, which represents 4 times 100.
The 2 is in the tens place or 2 times 10.
Then the final number is multiplied by 1, but computers work off of a base two numeral system.
In base 2, things work the exact same way, but because we only have 2 symbols to work with, each place is multiplied by 2, like 248163264128 and so on.
Now that you understand that, You also understand how other bases work, like base 16 or hexadecimal, which uses the digits 0 through 9 along with a through f, and is commonly used to represent binary values in a more concise way because each hexadecimal digit can translate into 4 bits.
And you also have base 64, which introduces even more letters and symbols to encode binary values, allowing developers to represent binary data like an image as a string of text.
While computers use base 2 under the hood.
They still need to represent base ten numbers for humans, and the most common way to do that is with floating point numbers.
Go ahead and execute 0.1 +0.2 in your favorite programming language.
The result should be 0.300004.
How could a computer make such a silly mistake?
Well, in science, numbers can get very big when talking about space and very small when talking about things like atoms.
We don't write these numbers out completely and instead use scientific notation, where an exponent raises it to an approximate value, making the number appear far more concise.
Computers use a similar approach with floating point numbers because they only have a limited amount space, either 32 bits for single precision or 64 for double precision, which is the default in languages like Python and JavaScript.
It's called a floating point because there's no fixed number of digits or after the decimal point, allowing developers to make a trade off between range and precision.
Some numbers like 0.01 can't be represented perfectly as a binary floating point, which is the reason we get those tiny rounding errors.
Now that you know how numbers work, we can start talking about logarithmic functions, which you might remember from algebra class.
To them.
Think of an actual log.
The log starts at 16 feet, then we saw it in half over and over again until we reach a length of 2.
Notice how when we try to draw a line through it, it's not straight, but rather it curves gradually.
In computer science, this is how many algorithms work like binary search.
What's interesting though is that if we know how many times we cut the log, raised 2 to the power of that value, in this case 4, to get the original length of the log.
That's called exponentiation, and logarithm is the exact opposite.
Imagine we don't know the exponent, We only know the original length and want to figure out how many times we'd have to cut the log to get a length of 2.
We could calculate that with a base 2 log on the original length, returning value of 4.
When it's base 2, it's called a binary logarithm.
However, in math, it's more common to use base 10, which is called the common logarithm.
That'll come in handy, but now let's shift gears to set theory.
A set is just an unordered collection of unique values.
The best example is a relational database where each table is a set of unique rows.
These tables can be joined together in a variety of different ways based on set theory.
Like to select records that match on both tables, you do an inner join, which is called an intersection in set theory.
Or to grab all matching records from both tables, you do a full outer join, which is a union in set theory.
When doing left and right joins, these concepts are combined, like by combining an intersection with the difference between the two sets.
Now one thing that's important to notice at this point is that we're talking about structures that have a finite number of elements, which falls under the umbrella of discrete math, as opposed to continuous math, like geometry and calculus, that deal with real numbers and approximations.
And that brings us to our next discrete topic combinatorics.
Simply put, this is all about counting things, especially when combining sets into combinations or permutations.
Like, if you have an app like Tinder, you might need to count all the possible combinations of matches as part of a more complex algorithm that figures out what the end user, or maybe you're building a globally distributed database and need to figure out how many database partitions you'll need around the world.
Ultimately, it's all about understanding how patterns can emerge.
What you're looking at here is the formula for the Fibonacci sequence.
A great exercise is to write a function that generates it.
Congrats, bro.
You just did combinatorics and unlock the secrets of the universe.
Engineers at Google use the same kind of logic to render tiles on tools like Google Maps, and the gods use this pattern all over the place in nature.
Combinatorics is closely related to graph theory.
A graph has two basic parts, nodes or vertices and edges that connect them together.
Like, a person might be a node, and an edge might be a relationship that connects them together.
Like you love your mom and your mom loves you back.
This is an undirected graph because the relationship goes both ways.
However, you might also love your OnlyFans girlfriend, but this would be a directed graph because that relationship only goes one way.
Edges can also be weighted, meaning one relationship is more important than the If a node can traverse back to itself, it's called cyclic.
Otherwise, it's known as acyclic.
As a programmer, you'll often need to build graphs from the ground up, but more importantly, know how to traverse them, like when using Dijkstra's algorithm to find the most efficient way to navigate through traffic.
But before you start writing graph traversal algorithms, you should know a little bit about complexity theory, which can tell us in theory how much time and memory an algorithm should use.
We use big o notation to express complexity, and when talking about time, the input represents the number of steps it will take to complete a task.
Like, if we read a single element from an array, that would give us o of 1 or constant time, which is extremely fast and simple.
If we need to loop over an array, that would give us o of n, where n is the length of the array.
But if for each iteration in that loop, we loop over the same array again, that would give us o of n squared, which would be far less efficient.
However, more sophisticated algorithms like binary search cut the search area in half after each iteration, providing us with logarithmic time.
Understanding how to measure complexity is essential for technical interviews and is just a good thing to think about in general.
But now let's move away from discrete math and talk about statistics, which is crucial if you want to do anything with artificial intelligence because machine learning is kind of just way of doing statistics.
Like, when you type in a chat gpt, it generates a response based on the probability that it fits the prompt provided by the user.
At the very least you should understand mean, median, and mode, and how standard deviation indicates how close values in a set are correlated to the mean.
There's a ton to learn beyond that, but what I found especially useful is the difference between linear regression and logistic regression.
In a linear regression, the goal is to predict a continuous value, like the amount of money you'll lose after buying a stock.
The relationship between the input and output variable is linear, and the idea is to find a line that best fits the dataset.
However, logistic regression is used for an entirely different set of problems like classification, maybe an app that predicts if an image is a hot dog or not a hot dog.
In this case, the relationship is not linear, but rather a sigmoid function, which might predict the probability that a boolean variable is true or false.
And that brings us to our final and most difficult topic, linear algebra, which comes into play in things like computer graphics and deep neural networks.
To comprehend it, you'll need to understand 3 weird words.
Scalar is a single numeric value.
A vector is a list of numbers like a 1 dimensional array.
And finally, a matrix is like a grid or 2 dimensional array that contains rows and columns of numeric values.
What's cool is that vectors can represent points and directions in a 3 space, while matrices can represent transformations that happen to these vectors.
When you move a player around in a video game, the lighting and shadows and the graphics change magically, but it's not magic.
It's linear algebra that's being distributed on your GPU.
Imagine you have a 2 d vector that's at point 2x3y.
It represents a single point in an image.
We can perform linear transformations here like scaling, translation, rotation, shear, and so on.
Let's imagine we now want to scale the point to a value of 4 x 6 y.
We can represent the scaling factors in a matrix, then represent the point as a column vector.
And now we can use matrix multiplication to scale the point to its target location.
Operations like this are also essential in things like cryptography, such as RSA encryption and are also essential in deep neural networks, which use vectors to represent features, then use matrix multiplication to propagate values between nodes in the network.
The underlying math is surprisingly simple, but requires a massive amount of computing power to handle the staggering amount of data required.
As you can see now, math is actually not that complicated, and the more you study it, the more the computer will reveal its magic tricks.
Thanks for watching, and I will see you in the next one.

Speaker 0: People often say you don't need to know any math to program a computer, and that's truthy. However, any sufficiently advanced technology is from magic, but magic isn't real. Math explains it all. Developers often avoid learning math because it looks scary, but it actually makes complicated magic like computer graphics and neural networks easier to understand. And not just that, but it unlocks the secrets of the entire physical universe.

There's a few abstract math concepts for programmers that you just can't ignore, and understanding them will make you think more like a true engineer. I'm no math genius. In fact, I'm the opposite, which makes me uniquely qualified to teach 10 essential math concepts using memes and other visual aids that almost anybody can understand. The first person who survives until the end cracks the code will win this one of a kind Balenciaga Fireship Hoodie. Let's jump right into topic number 1, Boolean algebra, which is used almost every time you write code.

A boolean is a binary variable that can have two possible values, true or false. Now there are 3 operators that you can use to work with them, and, or, and not, or conjunction, disjunction, and negation if you wanna be fancy. Imagine you're trying to get a girlfriend. We can use the boolean variables of rich and handsome to describe you. If you're both rich and handsome, you'll definitely get a girlfriend.

But if you're not rich and not handsome, you'll have to pay for an OnlyFans girlfriend. If you're rich or handsome, you can still get a girlfriend, but your selection is more limited. We can represent this logic in code with things like if statements, but we can also do it with Venn diagrams like you've been doing since grade school. And you can also create truth tables like this one here, which comes in handy in zombie apocalypse type situations. But that brings us to concept 2, numeral systems like base 2.

Throughout history, humans have come up with all kinds of clever ways to count things, but almost all of them use base 10 like the 10 fingers on your hands. Distance. Like in the number 423, the 4 is in the 100s place, which represents 4 times 100. The 2 is in the tens place or 2 times 10. Then the final number is multiplied by 1, but computers work off of a base two numeral system.

In base 2, things work the exact same way, but because we only have 2 symbols to work with, each place is multiplied by 2, like 248163264128 and so on. Now that you understand that, You also understand how other bases work, like base 16 or hexadecimal, which uses the digits 0 through 9 along with a through f, and is commonly used to represent binary values in a more concise way because each hexadecimal digit can translate into 4 bits. And you also have base 64, which introduces even more letters and symbols to encode binary values, allowing developers to represent binary data like an image as a string of text. While computers use base 2 under the hood. They still need to represent base ten numbers for humans, and the most common way to do that is with floating point numbers.

Go ahead and execute 0.1 +0.2 in your favorite programming language. The result should be 0.300004. How could a computer make such a silly mistake? Well, in science, numbers can get very big when talking about space and very small when talking about things like atoms. We don't write these numbers out completely and instead use scientific notation, where an exponent raises it to an approximate value, making the number appear far more concise.

Computers use a similar approach with floating point numbers because they only have a limited amount space, either 32 bits for single precision or 64 for double precision, which is the default in languages like Python and JavaScript. It's called a floating point because there's no fixed number of digits or after the decimal point, allowing developers to make a trade off between range and precision. Some numbers like 0.01 can't be represented perfectly as a binary floating point, which is the reason we get those tiny rounding errors. Now that you know how numbers work, we can start talking about logarithmic functions, which you might remember from algebra class. To them.

Think of an actual log. The log starts at 16 feet, then we saw it in half over and over again until we reach a length of 2. Notice how when we try to draw a line through it, it's not straight, but rather it curves gradually. In computer science, this is how many algorithms work like binary search. What's interesting though is that if we know how many times we cut the log, raised 2 to the power of that value, in this case 4, to get the original length of the log.

That's called exponentiation, and logarithm is the exact opposite. Imagine we don't know the exponent, We only know the original length and want to figure out how many times we'd have to cut the log to get a length of 2. We could calculate that with a base 2 log on the original length, returning value of 4. When it's base 2, it's called a binary logarithm. However, in math, it's more common to use base 10, which is called the common logarithm.

That'll come in handy, but now let's shift gears to set theory. A set is just an unordered collection of unique values. The best example is a relational database where each table is a set of unique rows. These tables can be joined together in a variety of different ways based on set theory. Like to select records that match on both tables, you do an inner join, which is called an intersection in set theory.

Or to grab all matching records from both tables, you do a full outer join, which is a union in set theory. When doing left and right joins, these concepts are combined, like by combining an intersection with the difference between the two sets. Now one thing that's important to notice at this point is that we're talking about structures that have a finite number of elements, which falls under the umbrella of discrete math, as opposed to continuous math, like geometry and calculus, that deal with real numbers and approximations. And that brings us to our next discrete topic combinatorics. Simply put, this is all about counting things, especially when combining sets into combinations or permutations.

Like, if you have an app like Tinder, you might need to count all the possible combinations of matches as part of a more complex algorithm that figures out what the end user, or maybe you're building a globally distributed database and need to figure out how many database partitions you'll need around the world. Ultimately, it's all about understanding how patterns can emerge. What you're looking at here is the formula for the Fibonacci sequence. A great exercise is to write a function that generates it. Congrats, bro.

You just did combinatorics and unlock the secrets of the universe. Engineers at Google use the same kind of logic to render tiles on tools like Google Maps, and the gods use this pattern all over the place in nature. Combinatorics is closely related to graph theory. A graph has two basic parts, nodes or vertices and edges that connect them together. Like, a person might be a node, and an edge might be a relationship that connects them together.

Like you love your mom and your mom loves you back. This is an undirected graph because the relationship goes both ways. However, you might also love your OnlyFans girlfriend, but this would be a directed graph because that relationship only goes one way. Edges can also be weighted, meaning one relationship is more important than the If a node can traverse back to itself, it's called cyclic. Otherwise, it's known as acyclic.

As a programmer, you'll often need to build graphs from the ground up, but more importantly, know how to traverse them, like when using Dijkstra's algorithm to find the most efficient way to navigate through traffic. But before you start writing graph traversal algorithms, you should know a little bit about complexity theory, which can tell us in theory how much time and memory an algorithm should use. We use big o notation to express complexity, and when talking about time, the input represents the number of steps it will take to complete a task. Like, if we read a single element from an array, that would give us o of 1 or constant time, which is extremely fast and simple. If we need to loop over an array, that would give us o of n, where n is the length of the array.

But if for each iteration in that loop, we loop over the same array again, that would give us o of n squared, which would be far less efficient. However, more sophisticated algorithms like binary search cut the search area in half after each iteration, providing us with logarithmic time. Understanding how to measure complexity is essential for technical interviews and is just a good thing to think about in general. But now let's move away from discrete math and talk about statistics, which is crucial if you want to do anything with artificial intelligence because machine learning is kind of just way of doing statistics. Like, when you type in a chat gpt, it generates a response based on the probability that it fits the prompt provided by the user.

At the very least you should understand mean, median, and mode, and how standard deviation indicates how close values in a set are correlated to the mean. There's a ton to learn beyond that, but what I found especially useful is the difference between linear regression and logistic regression. In a linear regression, the goal is to predict a continuous value, like the amount of money you'll lose after buying a stock. The relationship between the input and output variable is linear, and the idea is to find a line that best fits the dataset. However, logistic regression is used for an entirely different set of problems like classification, maybe an app that predicts if an image is a hot dog or not a hot dog.

In this case, the relationship is not linear, but rather a sigmoid function, which might predict the probability that a boolean variable is true or false. And that brings us to our final and most difficult topic, linear algebra, which comes into play in things like computer graphics and deep neural networks. To comprehend it, you'll need to understand 3 weird words. Scalar is a single numeric value. A vector is a list of numbers like a 1 dimensional array.

And finally, a matrix is like a grid or 2 dimensional array that contains rows and columns of numeric values. What's cool is that vectors can represent points and directions in a 3 space, while matrices can represent transformations that happen to these vectors. When you move a player around in a video game, the lighting and shadows and the graphics change magically, but it's not magic. It's linear algebra that's being distributed on your GPU. Imagine you have a 2 d vector that's at point 2x3y.

It represents a single point in an image. We can perform linear transformations here like scaling, translation, rotation, shear, and so on. Let's imagine we now want to scale the point to a value of 4 x 6 y. We can represent the scaling factors in a matrix, then represent the point as a column vector. And now we can use matrix multiplication to scale the point to its target location.

Operations like this are also essential in things like cryptography, such as RSA encryption and are also essential in deep neural networks, which use vectors to represent features, then use matrix multiplication to propagate values between nodes in the network. The underlying math is surprisingly simple, but requires a massive amount of computing power to handle the staggering amount of data required. As you can see now, math is actually not that complicated, and the more you study it, the more the computer will reveal its magic tricks. Thanks for watching, and I will see you in the next one.
People often say you don't need to know any math to program a computer, and that's truthy. However, any sufficiently advanced technology is from magic, but magic isn't real. Math explains it all. Developers often avoid learning math because it looks scary, but it actually makes complicated magic like computer graphics and neural networks easier to understand. And not just that, but it unlocks the secrets of the entire physical universe. There's a few abstract math concepts for programmers that you just can't ignore, and understanding them will make you think more like a true engineer. I'm no math genius. In fact, I'm the opposite, which makes me uniquely qualified to teach 10 essential math concepts using memes and other visual aids that almost anybody can understand. The first person who survives until the end cracks the code will win this one of a kind Balenciaga Fireship Hoodie.
mathematics
artificial intelligence
teaching
machine learning
logic
computer science
education
Let's jump right into topic number 1, Boolean algebra, which is used almost every time you write code. A boolean is a binary variable that can have two possible values, true or false. Now there are 3 operators that you can use to work with them, and, or, and not, or conjunction, disjunction, and negation if you wanna be fancy. Imagine you're trying to get a girlfriend. We can use the boolean variables of rich and handsome to describe you. If you're both rich and handsome, you'll definitely get a girlfriend. But if you're not rich and not handsome, you'll have to pay for an OnlyFans girlfriend. If you're rich or handsome, you can still get a girlfriend, but your selection is more limited.
We can represent this logic in code with things like if statements, but we can also do it with Venn diagrams like you've been doing since grade school. And you can also create truth tables like this one here, which comes in handy in zombie apocalypse type situations. But that brings us to concept 2, numeral systems like base 2. Throughout history, humans have come up with all kinds of clever ways to count things, but almost all of them use base 10 like the 10 fingers on your hands. Distance. Like in the number 423, the 4 is in the 100s place, which represents 4 times 100. The 2 is in the tens place or 2 times 10. Then the final number is multiplied by 1, but computers work off of a base two numeral system. In base 2, things work the exact same way, but because we only have 2 symbols to work with, each place is multiplied by 2, like 248163264128 and so on. Now that you understand that, You also understand how other bases work, like base 16 or hexadecimal, which uses the digits 0 through 9 along with a through f, and is commonly used to represent binary values in a more concise way because each hexadecimal digit can translate into 4 bits.
logic
measurement
mathematics
statistics
logical reasoning
And you also have base 64, which introduces even more letters and symbols to encode binary values, allowing developers to represent binary data like an image as a string of text.
While computers use base 2 under the hood. They still need to represent base ten numbers for humans, and the most common way to do that is with floating point numbers. Go ahead and execute 0.1 +0.2 in your favorite programming language. The result should be 0.300004. How could a computer make such a silly mistake? Well, in science, numbers can get very big when talking about space and very small when talking about things like atoms. We don't write these numbers out completely and instead use scientific notation, where an exponent raises it to an approximate value, making the number appear far more concise. Computers use a similar approach with floating point numbers because they only have a limited amount space, either 32 bits for single precision or 64 for double precision, which is the default in languages like Python and JavaScript. It's called a floating point because there's no fixed number of digits or after the decimal point, allowing developers to make a trade off between range and precision. Some numbers like 0.01 can't be represented perfectly as a binary floating point, which is the reason we get those tiny rounding errors. Now that you know how numbers work, we can start talking about logarithmic functions, which you might remember from algebra class. To them. Think of an actual log. The log starts at 16 feet, then we saw it in half over and over again until we reach a length of 2. Notice how when we try to draw a line through it, it's not straight, but rather it curves gradually. In computer science, this is how many algorithms work like binary search.
mathematics
trees
computer science
programming
What's interesting though is that if we know how many times we cut the log, raised 2 to the power of that value, in this case 4, to get the original length of the log. That's called exponentiation, and logarithm is the exact opposite. Imagine we don't know the exponent, We only know the original length and want to figure out how many times we'd have to cut the log to get a length of 2. We could calculate that with a base 2 log on the original length, returning value of 4. When it's base 2, it's called a binary logarithm. However, in math, it's more common to use base 10, which is called the common logarithm. That'll come in handy, but now let's shift gears to set theory.
A set is just an unordered collection of unique values. The best example is a relational database where each table is a set of unique rows. These tables can be joined together in a variety of different ways based on set theory. Like to select records that match on both tables, you do an inner join, which is called an intersection in set theory.
databases
Or to grab all matching records from both tables, you do a full outer join, which is a union in set theory. When doing left and right joins, these concepts are combined, like by combining an intersection with the difference between the two sets. Now one thing that's important to notice at this point is that we're talking about structures that have a finite number of elements, which falls under the umbrella of discrete math, as opposed to continuous math, like geometry and calculus, that deal with real numbers and approximations. And that brings us to our next discrete topic combinatorics. Simply put, this is all about counting things, especially when combining sets into combinations or permutations. Like, if you have an app like Tinder, you might need to count all the possible combinations of matches as part of a more complex algorithm that figures out what the end user, or maybe you're building a globally distributed database and need to figure out how many database partitions you'll need around the world. Ultimately, it's all about understanding how patterns can emerge. What you're looking at here is the formula for the Fibonacci sequence. A great exercise is to write a function that generates it. Congrats, bro. You just did combinatorics and unlock the secrets of the universe. Engineers at Google use the same kind of logic to render tiles on tools like Google Maps, and the gods use this pattern all over the place in nature.
databases
geometry
mathematics
logic
data
evolution
Combinatorics is closely related to graph theory. A graph has two basic parts, nodes or vertices and edges that connect them together. Like, a person might be a node, and an edge might be a relationship that connects them together.
Like you love your mom and your mom loves you back. This is an undirected graph because the relationship goes both ways. However, you might also love your OnlyFans girlfriend, but this would be a directed graph because that relationship only goes one way. Edges can also be weighted, meaning one relationship is more important than the If a node can traverse back to itself, it's called cyclic. Otherwise, it's known as acyclic. As a programmer, you'll often need to build graphs from the ground up, but more importantly, know how to traverse them, like when using Dijkstra's algorithm to find the most efficient way to navigate through traffic.
relationships
geometry
But before you start writing graph traversal algorithms, you should know a little bit about complexity theory, which can tell us in theory how much time and memory an algorithm should use.
We use big o notation to express complexity, and when talking about time, the input represents the number of steps it will take to complete a task. Like, if we read a single element from an array, that would give us o of 1 or constant time, which is extremely fast and simple.
mathematics
programming
If we need to loop over an array, that would give us o of n, where n is the length of the array. But if for each iteration in that loop, we loop over the same array again, that would give us o of n squared, which would be far less efficient.
However, more sophisticated algorithms like binary search cut the search area in half after each iteration, providing us with logarithmic time. Understanding how to measure complexity is essential for technical interviews and is just a good thing to think about in general. But now let's move away from discrete math and talk about statistics, which is crucial if you want to do anything with artificial intelligence because machine learning is kind of just way of doing statistics. Like, when you type in a chat gpt, it generates a response based on the probability that it fits the prompt provided by the user.
machine learning
artificial intelligence
statistics
deep learning
neural networks
data
At the very least you should understand mean, median, and mode, and how standard deviation indicates how close values in a set are correlated to the mean. There's a ton to learn beyond that, but what I found especially useful is the difference between linear regression and logistic regression. In a linear regression, the goal is to predict a continuous value, like the amount of money you'll lose after buying a stock.
The relationship between the input and output variable is linear, and the idea is to find a line that best fits the dataset. However, logistic regression is used for an entirely different set of problems like classification, maybe an app that predicts if an image is a hot dog or not a hot dog. In this case, the relationship is not linear, but rather a sigmoid function, which might predict the probability that a boolean variable is true or false. And that brings us to our final and most difficult topic, linear algebra, which comes into play in things like computer graphics and deep neural networks. To comprehend it, you'll need to understand 3 weird words. Scalar is a single numeric value. A vector is a list of numbers like a 1 dimensional array.
data analysis
mathematics
probability
geometry
And finally, a matrix is like a grid or 2 dimensional array that contains rows and columns of numeric values. What's cool is that vectors can represent points and directions in a 3 space, while matrices can represent transformations that happen to these vectors. When you move a player around in a video game, the lighting and shadows and the graphics change magically, but it's not magic. It's linear algebra that's being distributed on your GPU. Imagine you have a 2 d vector that's at point 2x3y. It represents a single point in an image. We can perform linear transformations here like scaling, translation, rotation, shear, and so on. Let's imagine we now want to scale the point to a value of 4 x 6 y. We can represent the scaling factors in a matrix, then represent the point as a column vector. And now we can use matrix multiplication to scale the point to its target location. Operations like this are also essential in things like cryptography, such as RSA encryption and are also essential in deep neural networks, which use vectors to represent features, then use matrix multiplication to propagate values between nodes in the network. The underlying math is surprisingly simple, but requires a massive amount of computing power to handle the staggering amount of data required. As you can see now, math is actually not that complicated, and the more you study it, the more the computer will reveal its magic tricks. Thanks for watching, and I will see you in the next one.
mathematics
geometry
video gaming
neural networks
machine learning
animation
computer science
People often say you don't need to know any math to program a computer, and that's truthy. However, any sufficiently advanced technology is from magic, but magic isn't real. Math explains it all. Developers often avoid learning math because it looks scary, but it actually makes complicated magic like computer graphics and neural networks easier to understand. And not just that, but it unlocks the secrets of the entire physical universe. There's a few abstract math concepts for programmers that you just can't ignore, and understanding them will make you think more like a true engineer. I'm no math genius. In fact, I'm the opposite, which makes me uniquely qualified to teach 10 essential math concepts using memes and other visual aids that almost anybody can understand. The first person who survives until the end cracks the code will win this one of a kind Balenciaga Fireship Hoodie. Let's jump right into topic number 1, Boolean algebra, which is used almost every time you write code. A boolean is a binary variable that can have two possible values, true or false. Now there are 3 operators that you can use to work with them, and, or, and not, or conjunction, disjunction, and negation if you wanna be fancy. Imagine you're trying to get a girlfriend. We can use the boolean variables of rich and handsome to describe you. If you're both rich and handsome, you'll definitely get a girlfriend. But if you're not rich and not handsome, you'll have to pay for an OnlyFans girlfriend. If you're rich or handsome, you can still get a girlfriend, but your selection is more limited. We can represent this logic in code with things like if statements, but we can also do it with Venn diagrams like you've been doing since grade school. And you can also create truth tables like this one here, which comes in handy in zombie apocalypse type situations. But that brings us to concept 2, numeral systems like base 2. Throughout history, humans have come up with all kinds of clever ways to count things, but almost all of them use base 10 like the 10 fingers on your hands. Distance. Like in the number 423, the 4 is in the 100s place, which represents 4 times 100. The 2 is in the tens place or 2 times 10. Then the final number is multiplied by 1, but computers work off of a base two numeral system. In base 2, things work the exact same way, but because we only have 2 symbols to work with, each place is multiplied by 2, like 248163264128 and so on. Now that you understand that, You also understand how other bases work, like base 16 or hexadecimal, which uses the digits 0 through 9 along with a through f, and is commonly used to represent binary values in a more concise way because each hexadecimal digit can translate into 4 bits. And you also have base 64, which introduces even more letters and symbols to encode binary values, allowing developers to represent binary data like an image as a string of text. While computers use base 2 under the hood. They still need to represent base ten numbers for humans, and the most common way to do that is with floating point numbers. Go ahead and execute 0.1 +0.2 in your favorite programming language. The result should be 0.300004. How could a computer make such a silly mistake? Well, in science, numbers can get very big when talking about space and very small when talking about things like atoms. We don't write these numbers out completely and instead use scientific notation, where an exponent raises it to an approximate value, making the number appear far more concise. Computers use a similar approach with floating point numbers because they only have a limited amount space, either 32 bits for single precision or 64 for double precision, which is the default in languages like Python and JavaScript. It's called a floating point because there's no fixed number of digits or after the decimal point, allowing developers to make a trade off between range and precision. Some numbers like 0.01 can't be represented perfectly as a binary floating point, which is the reason we get those tiny rounding errors. Now that you know how numbers work, we can start talking about logarithmic functions, which you might remember from algebra class. To them. Think of an actual log. The log starts at 16 feet, then we saw it in half over and over again until we reach a length of 2. Notice how when we try to draw a line through it, it's not straight, but rather it curves gradually. In computer science, this is how many algorithms work like binary search. What's interesting though is that if we know how many times we cut the log, raised 2 to the power of that value, in this case 4, to get the original length of the log. That's called exponentiation, and logarithm is the exact opposite. Imagine we don't know the exponent, We only know the original length and want to figure out how many times we'd have to cut the log to get a length of 2. We could calculate that with a base 2 log on the original length, returning value of 4. When it's base 2, it's called a binary logarithm. However, in math, it's more common to use base 10, which is called the common logarithm. That'll come in handy, but now let's shift gears to set theory. A set is just an unordered collection of unique values. The best example is a relational database where each table is a set of unique rows. These tables can be joined together in a variety of different ways based on set theory. Like to select records that match on both tables, you do an inner join, which is called an intersection in set theory. Or to grab all matching records from both tables, you do a full outer join, which is a union in set theory. When doing left and right joins, these concepts are combined, like by combining an intersection with the difference between the two sets. Now one thing that's important to notice at this point is that we're talking about structures that have a finite number of elements, which falls under the umbrella of discrete math, as opposed to continuous math, like geometry and calculus, that deal with real numbers and approximations. And that brings us to our next discrete topic combinatorics. Simply put, this is all about counting things, especially when combining sets into combinations or permutations. Like, if you have an app like Tinder, you might need to count all the possible combinations of matches as part of a more complex algorithm that figures out what the end user, or maybe you're building a globally distributed database and need to figure out how many database partitions you'll need around the world. Ultimately, it's all about understanding how patterns can emerge. What you're looking at here is the formula for the Fibonacci sequence. A great exercise is to write a function that generates it. Congrats, bro. You just did combinatorics and unlock the secrets of the universe. Engineers at Google use the same kind of logic to render tiles on tools like Google Maps, and the gods use this pattern all over the place in nature. Combinatorics is closely related to graph theory. A graph has two basic parts, nodes or vertices and edges that connect them together. Like, a person might be a node, and an edge might be a relationship that connects them together. Like you love your mom and your mom loves you back. This is an undirected graph because the relationship goes both ways. However, you might also love your OnlyFans girlfriend, but this would be a directed graph because that relationship only goes one way. Edges can also be weighted, meaning one relationship is more important than the If a node can traverse back to itself, it's called cyclic. Otherwise, it's known as acyclic. As a programmer, you'll often need to build graphs from the ground up, but more importantly, know how to traverse them, like when using Dijkstra's algorithm to find the most efficient way to navigate through traffic. But before you start writing graph traversal algorithms, you should know a little bit about complexity theory, which can tell us in theory how much time and memory an algorithm should use. We use big o notation to express complexity, and when talking about time, the input represents the number of steps it will take to complete a task. Like, if we read a single element from an array, that would give us o of 1 or constant time, which is extremely fast and simple. If we need to loop over an array, that would give us o of n, where n is the length of the array. But if for each iteration in that loop, we loop over the same array again, that would give us o of n squared, which would be far less efficient. However, more sophisticated algorithms like binary search cut the search area in half after each iteration, providing us with logarithmic time. Understanding how to measure complexity is essential for technical interviews and is just a good thing to think about in general. But now let's move away from discrete math and talk about statistics, which is crucial if you want to do anything with artificial intelligence because machine learning is kind of just way of doing statistics. Like, when you type in a chat gpt, it generates a response based on the probability that it fits the prompt provided by the user. At the very least you should understand mean, median, and mode, and how standard deviation indicates how close values in a set are correlated to the mean. There's a ton to learn beyond that, but what I found especially useful is the difference between linear regression and logistic regression. In a linear regression, the goal is to predict a continuous value, like the amount of money you'll lose after buying a stock. The relationship between the input and output variable is linear, and the idea is to find a line that best fits the dataset. However, logistic regression is used for an entirely different set of problems like classification, maybe an app that predicts if an image is a hot dog or not a hot dog. In this case, the relationship is not linear, but rather a sigmoid function, which might predict the probability that a boolean variable is true or false. And that brings us to our final and most difficult topic, linear algebra, which comes into play in things like computer graphics and deep neural networks. To comprehend it, you'll need to understand 3 weird words. Scalar is a single numeric value. A vector is a list of numbers like a 1 dimensional array. And finally, a matrix is like a grid or 2 dimensional array that contains rows and columns of numeric values. What's cool is that vectors can represent points and directions in a 3 space, while matrices can represent transformations that happen to these vectors. When you move a player around in a video game, the lighting and shadows and the graphics change magically, but it's not magic. It's linear algebra that's being distributed on your GPU. Imagine you have a 2 d vector that's at point 2x3y. It represents a single point in an image. We can perform linear transformations here like scaling, translation, rotation, shear, and so on. Let's imagine we now want to scale the point to a value of 4 x 6 y. We can represent the scaling factors in a matrix, then represent the point as a column vector. And now we can use matrix multiplication to scale the point to its target location. Operations like this are also essential in things like cryptography, such as RSA encryption and are also essential in deep neural networks, which use vectors to represent features, then use matrix multiplication to propagate values between nodes in the network. The underlying math is surprisingly simple, but requires a massive amount of computing power to handle the staggering amount of data required. As you can see now, math is actually not that complicated, and the more you study it, the more the computer will reveal its magic tricks. Thanks for watching, and I will see you in the next one.
People
people
often
often
say
say
you
you
don't
don't
need
need
to
to
know
know
any
any
math
math
to
to
program
program
a
a
computer,
computer
and
and
that's
that's
truthy.
truthy
However,
however
any
any
sufficiently
sufficiently
advanced
advanced
technology
technology
is
is
from
from
magic,
magic
but
but
magic
magic
isn't
isn't
real.
real
Math
math
explains
explains
it
it
all.
all
Developers
developers
often
often
avoid
avoid
learning
learning
math
math
because
because
it
it
looks
looks
scary,
scary
but
but
it
it
actually
actually
makes
makes
complicated
complicated
magic
magic
like
like
computer
computer
graphics
graphics
and
and
neural
neural
networks
networks
easier
easier
to
to
understand.
understand
And
and
not
not
just
just
that,
that
but
but
it
it
unlocks
unlocks
the
the
secrets
secrets
of
of
the
the
entire
entire
physical
physical
universe.
universe
There's
there's
a
a
few
few
abstract
abstract
math
math
concepts
concepts
for
for
programmers
programmers
that
that
you
you
just
just
can't
can't
ignore,
ignore
and
and
understanding
understanding
them
them
will
will
make
make
you
you
think
think
more
more
like
like
a
a
true
true
engineer.
engineer
I'm
i'm
no
no
math
math
genius.
genius
In
in
fact,
fact
I'm
i'm
the
the
opposite,
opposite
which
which
makes
makes
me
me
uniquely
uniquely
qualified
qualified
to
to
teach
teach
10
10
essential
essential
math
math
concepts
concepts
using
using
memes
memes
and
and
other
other
visual
visual
aids
aids
that
that
almost
almost
anybody
anybody
can
can
understand.
understand
The
the
first
first
person
person
who
who
survives
survives
until
until
the
the
end
end
cracks
cracks
the
the
code
code
will
will
win
win
this
this
one
one
of
of
a
a
kind
kind
Balenciaga
balenciaga
Fireship
fireship
Hoodie.
hoodie
Let's
let's
jump
jump
right
right
into
into
topic
topic
number
number
1,
1
Boolean
boolean
algebra,
algebra
which
which
is
is
used
used
almost
almost
every
every
time
time
you
you
write
write
code.
code
A
a
boolean
boolean
is
is
a
a
binary
binary
variable
variable
that
that
can
can
have
have
two
two
possible
possible
values,
values
true
true
or
or
false.
false
Now
now
there
there
are
are
3
3
operators
operators
that
that
you
you
can
can
use
use
to
to
work
work
with
with
them,
them
and,
and
or,
or
and
and
not,
not
or
or
conjunction,
conjunction
disjunction,
disjunction
and
and
negation
negation
if
if
you
you
wanna
wanna
be
be
fancy.
fancy
Imagine
imagine
you're
you're
trying
trying
to
to
get
get
a
a
girlfriend.
girlfriend
We
we
can
can
use
use
the
the
boolean
boolean
variables
variables
of
of
rich
rich
and
and
handsome
handsome
to
to
describe
describe
you.
you
If
if
you're
you're
both
both
rich
rich
and
and
handsome,
handsome
you'll
you'll
definitely
definitely
get
get
a
a
girlfriend.
girlfriend
But
but
if
if
you're
you're
not
not
rich
rich
and
and
not
not
handsome,
handsome
you'll
you'll
have
have
to
to
pay
pay
for
for
an
an
OnlyFans
onlyfans
girlfriend.
girlfriend
If
if
you're
you're
rich
rich
or
or
handsome,
handsome
you
you
can
can
still
still
get
get
a
a
girlfriend,
girlfriend
but
but
your
your
selection
selection
is
is
more
more
limited.
limited
We
we
can
can
represent
represent
this
this
logic
logic
in
in
code
code
with
with
things
things
like
like
if
if
statements,
statements
but
but
we
we
can
can
also
also
do
do
it
it
with
with
Venn
venn
diagrams
diagrams
like
like
you've
you've
been
been
doing
doing
since
since
grade
grade
school.
school
And
and
you
you
can
can
also
also
create
create
truth
truth
tables
tables
like
like
this
this
one
one
here,
here
which
which
comes
comes
in
in
handy
handy
in
in
zombie
zombie
apocalypse
apocalypse
type
type
situations.
situations
But
but
that
that
brings
brings
us
us
to
to
concept
concept
2,
2
numeral
numeral
systems
systems
like
like
base
base
2.
2
Throughout
throughout
history,
history
humans
humans
have
have
come
come
up
up
with
with
all
all
kinds
kinds
of
of
clever
clever
ways
ways
to
to
count
count
things,
things
but
but
almost
almost
all
all
of
of
them
them
use
use
base
base
10
10
like
like
the
the
10
10
fingers
fingers
on
on
your
your
hands.
hands
Distance.
distance
Like
like
in
in
the
the
number
number
423,
423
the
the
4
4
is
is
in
in
the
the
100s
100s
place,
place
which
which
represents
represents
4
4
times
times
100.
100
The
the
2
2
is
is
in
in
the
the
tens
tens
place
place
or
or
2
2
times
times
10.
10
Then
then
the
the
final
final
number
number
is
is
multiplied
multiplied
by
by
1,
1
but
but
computers
computers
work
work
off
off
of
of
a
a
base
base
two
two
numeral
numeral
system.
system
In
in
base
base
2,
2
things
things
work
work
the
the
exact
exact
same
same
way,
way
but
but
because
because
we
we
only
only
have
have
2
2
symbols
symbols
to
to
work
work
with,
with
each
each
place
place
is
is
multiplied
multiplied
by
by
2,
2
like
like
248163264128
248163264128
and
and
so
so
on.
on
Now
now
that
that
you
you
understand
understand
that,
that
You
you
also
also
understand
understand
how
how
other
other
bases
bases
work,
work
like
like
base
base
16
16
or
or
hexadecimal,
hexadecimal
which
which
uses
uses
the
the
digits
digits
0
0
through
through
9
9
along
along
with
with
a
a
through
through
f,
f
and
and
is
is
commonly
commonly
used
used
to
to
represent
represent
binary
binary
values
values
in
in
a
a
more
more
concise
concise
way
way
because
because
each
each
hexadecimal
hexadecimal
digit
digit
can
can
translate
translate
into
into
4
4
bits.
bits
And
and
you
you
also
also
have
have
base
base
64,
64
which
which
introduces
introduces
even
even
more
more
letters
letters
and
and
symbols
symbols
to
to
encode
encode
binary
binary
values,
values
allowing
allowing
developers
developers
to
to
represent
represent
binary
binary
data
data
like
like
an
an
image
image
as
as
a
a
string
string
of
of
text.
text
While
while
computers
computers
use
use
base
base
2
2
under
under
the
the
hood.
hood
They
they
still
still
need
need
to
to
represent
represent
base
base
ten
ten
numbers
numbers
for
for
humans,
humans
and
and
the
the
most
most
common
common
way
way
to
to
do
do
that
that
is
is
with
with
floating
floating
point
point
numbers.
numbers
Go
go
ahead
ahead
and
and
execute
execute
0.1
0.1
+0.2
+0.2
in
in
your
your
favorite
favorite
programming
programming
language.
language
The
the
result
result
should
should
be
be
0.300004.
0.300004
How
how
could
could
a
a
computer
computer
make
make
such
such
a
a
silly
silly
mistake?
mistake
Well,
well
in
in
science,
science
numbers
numbers
can
can
get
get
very
very
big
big
when
when
talking
talking
about
about
space
space
and
and
very
very
small
small
when
when
talking
talking
about
about
things
things
like
like
atoms.
atoms
We
we
don't
don't
write
write
these
these
numbers
numbers
out
out
completely
completely
and
and
instead
instead
use
use
scientific
scientific
notation,
notation
where
where
an
an
exponent
exponent
raises
raises
it
it
to
to
an
an
approximate
approximate
value,
value
making
making
the
the
number
number
appear
appear
far
far
more
more
concise.
concise
Computers
computers
use
use
a
a
similar
similar
approach
approach
with
with
floating
floating
point
point
numbers
numbers
because
because
they
they
only
only
have
have
a
a
limited
limited
amount
amount
space,
space
either
either
32
32
bits
bits
for
for
single
single
precision
precision
or
or
64
64
for
for
double
double
precision,
precision
which
which
is
is
the
the
default
default
in
in
languages
languages
like
like
Python
python
and
and
JavaScript.
javascript
It's
it's
called
called
a
a
floating
floating
point
point
because
because
there's
there's
no
no
fixed
fixed
number
number
of
of
digits
digits
or
or
after
after
the
the
decimal
decimal
point,
point
allowing
allowing
developers
developers
to
to
make
make
a
a
trade
trade
off
off
between
between
range
range
and
and
precision.
precision
Some
some
numbers
numbers
like
like
0.01
0.01
can't
can't
be
be
represented
represented
perfectly
perfectly
as
as
a
a
binary
binary
floating
floating
point,
point
which
which
is
is
the
the
reason
reason
we
we
get
get
those
those
tiny
tiny
rounding
rounding
errors.
errors
Now
now
that
that
you
you
know
know
how
how
numbers
numbers
work,
work
we
we
can
can
start
start
talking
talking
about
about
logarithmic
logarithmic
functions,
functions
which
which
you
you
might
might
remember
remember
from
from
algebra
algebra
class.
class
To
to
them.
them
Think
think
of
of
an
an
actual
actual
log.
log
The
the
log
log
starts
starts
at
at
16
16
feet,
feet
then
then
we
we
saw
saw
it
it
in
in
half
half
over
over
and
and
over
over
again
again
until
until
we
we
reach
reach
a
a
length
length
of
of
2.
2
Notice
notice
how
how
when
when
we
we
try
try
to
to
draw
draw
a
a
line
line
through
through
it,
it
it's
it's
not
not
straight,
straight
but
but
rather
rather
it
it
curves
curves
gradually.
gradually
In
in
computer
computer
science,
science
this
this
is
is
how
how
many
many
algorithms
algorithms
work
work
like
like
binary
binary
search.
search
What's
what's
interesting
interesting
though
though
is
is
that
that
if
if
we
we
know
know
how
how
many
many
times
times
we
we
cut
cut
the
the
log,
log
raised
raised
2
2
to
to
the
the
power
power
of
of
that
that
value,
value
in
in
this
this
case
case
4,
4
to
to
get
get
the
the
original
original
length
length
of
of
the
the
log.
log
That's
that's
called
called
exponentiation,
exponentiation
and
and
logarithm
logarithm
is
is
the
the
exact
exact
opposite.
opposite
Imagine
imagine
we
we
don't
don't
know
know
the
the
exponent,
exponent
We
we
only
only
know
know
the
the
original
original
length
length
and
and
want
want
to
to
figure
figure
out
out
how
how
many
many
times
times
we'd
we'd
have
have
to
to
cut
cut
the
the
log
log
to
to
get
get
a
a
length
length
of
of
2.
2
We
we
could
could
calculate
calculate
that
that
with
with
a
a
base
base
2
2
log
log
on
on
the
the
original
original
length,
length
returning
returning
value
value
of
of
4.
4
When
when
it's
it's
base
base
2,
2
it's
it's
called
called
a
a
binary
binary
logarithm.
logarithm
However,
however
in
in
math,
math
it's
it's
more
more
common
common
to
to
use
use
base
base
10,
10
which
which
is
is
called
called
the
the
common
common
logarithm.
logarithm
That'll
that'll
come
come
in
in
handy,
handy
but
but
now
now
let's
let's
shift
shift
gears
gears
to
to
set
set
theory.
theory
A
a
set
set
is
is
just
just
an
an
unordered
unordered
collection
collection
of
of
unique
unique
values.
values
The
the
best
best
example
example
is
is
a
a
relational
relational
database
database
where
where
each
each
table
table
is
is
a
a
set
set
of
of
unique
unique
rows.
rows
These
these
tables
tables
can
can
be
be
joined
joined
together
together
in
in
a
a
variety
variety
of
of
different
different
ways
ways
based
based
on
on
set
set
theory.
theory
Like
like
to
to
select
select
records
records
that
that
match
match
on
on
both
both
tables,
tables
you
you
do
do
an
an
inner
inner
join,
join
which
which
is
is
called
called
an
an
intersection
intersection
in
in
set
set
theory.
theory
Or
or
to
to
grab
grab
all
all
matching
matching
records
records
from
from
both
both
tables,
tables
you
you
do
do
a
a
full
full
outer
outer
join,
join
which
which
is
is
a
a
union
union
in
in
set
set
theory.
theory
When
when
doing
doing
left
left
and
and
right
right
joins,
joins
these
these
concepts
concepts
are
are
combined,
combined
like
like
by
by
combining
combining
an
an
intersection
intersection
with
with
the
the
difference
difference
between
between
the
the
two
two
sets.
sets
Now
now
one
one
thing
thing
that's
that's
important
important
to
to
notice
notice
at
at
this
this
point
point
is
is
that
that
we're
we're
talking
talking
about
about
structures
structures
that
that
have
have
a
a
finite
finite
number
number
of
of
elements,
elements
which
which
falls
falls
under
under
the
the
umbrella
umbrella
of
of
discrete
discrete
math,
math
as
as
opposed
opposed
to
to
continuous
continuous
math,
math
like
like
geometry
geometry
and
and
calculus,
calculus
that
that
deal
deal
with
with
real
real
numbers
numbers
and
and
approximations.
approximations
And
and
that
that
brings
brings
us
us
to
to
our
our
next
next
discrete
discrete
topic
topic
combinatorics.
combinatorics
Simply
simply
put,
put
this
this
is
is
all
all
about
about
counting
counting
things,
things
especially
especially
when
when
combining
combining
sets
sets
into
into
combinations
combinations
or
or
permutations.
permutations
Like,
like
if
if
you
you
have
have
an
an
app
app
like
like
Tinder,
tinder
you
you
might
might
need
need
to
to
count
count
all
all
the
the
possible
possible
combinations
combinations
of
of
matches
matches
as
as
part
part
of
of
a
a
more
more
complex
complex
algorithm
algorithm
that
that
figures
figures
out
out
what
what
the
the
end
end
user,
user
or
or
maybe
maybe
you're
you're
building
building
a
a
globally
globally
distributed
distributed
database
database
and
and
need
need
to
to
figure
figure
out
out
how
how
many
many
database
database
partitions
partitions
you'll
you'll
need
need
around
around
the
the
world.
world
Ultimately,
ultimately
it's
it's
all
all
about
about
understanding
understanding
how
how
patterns
patterns
can
can
emerge.
emerge
What
what
you're
you're
looking
looking
at
at
here
here
is
is
the
the
formula
formula
for
for
the
the
Fibonacci
fibonacci
sequence.
sequence
A
a
great
great
exercise
exercise
is
is
to
to
write
write
a
a
function
function
that
that
generates
generates
it.
it
Congrats,
congrats
bro.
bro
You
you
just
just
did
did
combinatorics
combinatorics
and
and
unlock
unlock
the
the
secrets
secrets
of
of
the
the
universe.
universe
Engineers
engineers
at
at
Google
google
use
use
the
the
same
same
kind
kind
of
of
logic
logic
to
to
render
render
tiles
tiles
on
on
tools
tools
like
like
Google
google
Maps,
maps
and
and
the
the
gods
gods
use
use
this
this
pattern
pattern
all
all
over
over
the
the
place
place
in
in
nature.
nature
Combinatorics
combinatorics
is
is
closely
closely
related
related
to
to
graph
graph
theory.
theory
A
a
graph
graph
has
has
two
two
basic
basic
parts,
parts
nodes
nodes
or
or
vertices
vertices
and
and
edges
edges
that
that
connect
connect
them
them
together.
together
Like,
like
a
a
person
person
might
might
be
be
a
a
node,
node
and
and
an
an
edge
edge
might
might
be
be
a
a
relationship
relationship
that
that
connects
connects
them
them
together.
together
Like
like
you
you
love
love
your
your
mom
mom
and
and
your
your
mom
mom
loves
loves
you
you
back.
back
This
this
is
is
an
an
undirected
undirected
graph
graph
because
because
the
the
relationship
relationship
goes
goes
both
both
ways.
ways
However,
however
you
you
might
might
also
also
love
love
your
your
OnlyFans
onlyfans
girlfriend,
girlfriend
but
but
this
this
would
would
be
be
a
a
directed
directed
graph
graph
because
because
that
that
relationship
relationship
only
only
goes
goes
one
one
way.
way
Edges
edges
can
can
also
also
be
be
weighted,
weighted
meaning
meaning
one
one
relationship
relationship
is
is
more
more
important
important
than
than
the
the
If
if
a
a
node
node
can
can
traverse
traverse
back
back
to
to
itself,
itself
it's
it's
called
called
cyclic.
cyclic
Otherwise,
otherwise
it's
it's
known
known
as
as
acyclic.
acyclic
As
as
a
a
programmer,
programmer
you'll
you'll
often
often
need
need
to
to
build
build
graphs
graphs
from
from
the
the
ground
ground
up,
up
but
but
more
more
importantly,
importantly
know
know
how
how
to
to
traverse
traverse
them,
them
like
like
when
when
using
using
Dijkstra's
dijkstra's
algorithm
algorithm
to
to
find
find
the
the
most
most
efficient
efficient
way
way
to
to
navigate
navigate
through
through
traffic.
traffic
But
but
before
before
you
you
start
start
writing
writing
graph
graph
traversal
traversal
algorithms,
algorithms
you
you
should
should
know
know
a
a
little
little
bit
bit
about
about
complexity
complexity
theory,
theory
which
which
can
can
tell
tell
us
us
in
in
theory
theory
how
how
much
much
time
time
and
and
memory
memory
an
an
algorithm
algorithm
should
should
use.
use
We
we
use
use
big
big
o
o
notation
notation
to
to
express
express
complexity,
complexity
and
and
when
when
talking
talking
about
about
time,
time
the
the
input
input
represents
represents
the
the
number
number
of
of
steps
steps
it
it
will
will
take
take
to
to
complete
complete
a
a
task.
task
Like,
like
if
if
we
we
read
read
a
a
single
single
element
element
from
from
an
an
array,
array
that
that
would
would
give
give
us
us
o
o
of
of
1
1
or
or
constant
constant
time,
time
which
which
is
is
extremely
extremely
fast
fast
and
and
simple.
simple
If
if
we
we
need
need
to
to
loop
loop
over
over
an
an
array,
array
that
that
would
would
give
give
us
us
o
o
of
of
n,
n
where
where
n
n
is
is
the
the
length
length
of
of
the
the
array.
array
But
but
if
if
for
for
each
each
iteration
iteration
in
in
that
that
loop,
loop
we
we
loop
loop
over
over
the
the
same
same
array
array
again,
again
that
that
would
would
give
give
us
us
o
o
of
of
n
n
squared,
squared
which
which
would
would
be
be
far
far
less
less
efficient.
efficient
However,
however
more
more
sophisticated
sophisticated
algorithms
algorithms
like
like
binary
binary
search
search
cut
cut
the
the
search
search
area
area
in
in
half
half
after
after
each
each
iteration,
iteration
providing
providing
us
us
with
with
logarithmic
logarithmic
time.
time
Understanding
understanding
how
how
to
to
measure
measure
complexity
complexity
is
is
essential
essential
for
for
technical
technical
interviews
interviews
and
and
is
is
just
just
a
a
good
good
thing
thing
to
to
think
think
about
about
in
in
general.
general
But
but
now
now
let's
let's
move
move
away
away
from
from
discrete
discrete
math
math
and
and
talk
talk
about
about
statistics,
statistics
which
which
is
is
crucial
crucial
if
if
you
you
want
want
to
to
do
do
anything
anything
with
with
artificial
artificial
intelligence
intelligence
because
because
machine
machine
learning
learning
is
is
kind
kind
of
of
just
just
way
way
of
of
doing
doing
statistics.
statistics
Like,
like
when
when
you
you
type
type
in
in
a
a
chat
chat
gpt,
gpt
it
it
generates
generates
a
a
response
response
based
based
on
on
the
the
probability
probability
that
that
it
it
fits
fits
the
the
prompt
prompt
provided
provided
by
by
the
the
user.
user
At
at
the
the
very
very
least
least
you
you
should
should
understand
understand
mean,
mean
median,
median
and
and
mode,
mode
and
and
how
how
standard
standard
deviation
deviation
indicates
indicates
how
how
close
close
values
values
in
in
a
a
set
set
are
are
correlated
correlated
to
to
the
the
mean.
mean
There's
there's
a
a
ton
ton
to
to
learn
learn
beyond
beyond
that,
that
but
but
what
what
I
i
found
found
especially
especially
useful
useful
is
is
the
the
difference
difference
between
between
linear
linear
regression
regression
and
and
logistic
logistic
regression.
regression
In
in
a
a
linear
linear
regression,
regression
the
the
goal
goal
is
is
to
to
predict
predict
a
a
continuous
continuous
value,
value
like
like
the
the
amount
amount
of
of
money
money
you'll
you'll
lose
lose
after
after
buying
buying
a
a
stock.
stock
The
the
relationship
relationship
between
between
the
the
input
input
and
and
output
output
variable
variable
is
is
linear,
linear
and
and
the
the
idea
idea
is
is
to
to
find
find
a
a
line
line
that
that
best
best
fits
fits
the
the
dataset.
dataset
However,
however
logistic
logistic
regression
regression
is
is
used
used
for
for
an
an
entirely
entirely
different
different
set
set
of
of
problems
problems
like
like
classification,
classification
maybe
maybe
an
an
app
app
that
that
predicts
predicts
if
if
an
an
image
image
is
is
a
a
hot
hot
dog
dog
or
or
not
not
a
a
hot
hot
dog.
dog
In
in
this
this
case,
case
the
the
relationship
relationship
is
is
not
not
linear,
linear
but
but
rather
rather
a
a
sigmoid
sigmoid
function,
function
which
which
might
might
predict
predict
the
the
probability
probability
that
that
a
a
boolean
boolean
variable
variable
is
is
true
true
or
or
false.
false
And
and
that
that
brings
brings
us
us
to
to
our
our
final
final
and
and
most
most
difficult
difficult
topic,
topic
linear
linear
algebra,
algebra
which
which
comes
comes
into
into
play
play
in
in
things
things
like
like
computer
computer
graphics
graphics
and
and
deep
deep
neural
neural
networks.
networks
To
to
comprehend
comprehend
it,
it
you'll
you'll
need
need
to
to
understand
understand
3
3
weird
weird
words.
words
Scalar
scalar
is
is
a
a
single
single
numeric
numeric
value.
value
A
a
vector
vector
is
is
a
a
list
list
of
of
numbers
numbers
like
like
a
a
1
1
dimensional
dimensional
array.
array
And
and
finally,
finally
a
a
matrix
matrix
is
is
like
like
a
a
grid
grid
or
or
2
2
dimensional
dimensional
array
array
that
that
contains
contains
rows
rows
and
and
columns
columns
of
of
numeric
numeric
values.
values
What's
what's
cool
cool
is
is
that
that
vectors
vectors
can
can
represent
represent
points
points
and
and
directions
directions
in
in
a
a
3
3
space,
space
while
while
matrices
matrices
can
can
represent
represent
transformations
transformations
that
that
happen
happen
to
to
these
these
vectors.
vectors
When
when
you
you
move
move
a
a
player
player
around
around
in
in
a
a
video
video
game,
game
the
the
lighting
lighting
and
and
shadows
shadows
and
and
the
the
graphics
graphics
change
change
magically,
magically
but
but
it's
it's
not
not
magic.
magic
It's
it's
linear
linear
algebra
algebra
that's
that's
being
being
distributed
distributed
on
on
your
your
GPU.
gpu
Imagine
imagine
you
you
have
have
a
a
2
2
d
d
vector
vector
that's
that's
at
at
point
point
2x3y.
2x3y
It
it
represents
represents
a
a
single
single
point
point
in
in
an
an
image.
image
We
we
can
can
perform
perform
linear
linear
transformations
transformations
here
here
like
like
scaling,
scaling
translation,
translation
rotation,
rotation
shear,
shear
and
and
so
so
on.
on
Let's
let's
imagine
imagine
we
we
now
now
want
want
to
to
scale
scale
the
the
point
point
to
to
a
a
value
value
of
of
4
4
x
x
6
6
y.
y
We
we
can
can
represent
represent
the
the
scaling
scaling
factors
factors
in
in
a
a
matrix,
matrix
then
then
represent
represent
the
the
point
point
as
as
a
a
column
column
vector.
vector
And
and
now
now
we
we
can
can
use
use
matrix
matrix
multiplication
multiplication
to
to
scale
scale
the
the
point
point
to
to
its
its
target
target
location.
location
Operations
operations
like
like
this
this
are
are
also
also
essential
essential
in
in
things
things
like
like
cryptography,
cryptography
such
such
as
as
RSA
rsa
encryption
encryption
and
and
are
are
also
also
essential
essential
in
in
deep
deep
neural
neural
networks,
networks
which
which
use
use
vectors
vectors
to
to
represent
represent
features,
features
then
then
use
use
matrix
matrix
multiplication
multiplication
to
to
propagate
propagate
values
values
between
between
nodes
nodes
in
in
the
the
network.
network
The
the
underlying
underlying
math
math
is
is
surprisingly
surprisingly
simple,
simple
but
but
requires
requires
a
a
massive
massive
amount
amount
of
of
computing
computing
power
power
to
to
handle
handle
the
the
staggering
staggering
amount
amount
of
of
data
data
required.
required
As
as
you
you
can
can
see
see
now,
now
math
math
is
is
actually
actually
not
not
that
that
complicated,
complicated
and
and
the
the
more
more
you
you
study
study
it,
it
the
the
more
more
the
the
computer
computer
will
will
reveal
reveal
its
its
magic
magic
tricks.
tricks
Thanks
thanks
for
for
watching,
watching
and
and
I
i
will
will
see
see
you
you
in
in
the
the
next
next
one.
one
success
The speaker explains the concept of mathematics and the use of base 2, fixed precision numbers, and analytics. They also discuss the concept of structures with a finite number of elements and the use of linear and logistic regression in algorithms. The speaker emphasizes the importance of understanding complexity in machine learning and analytics for technical interviews and concludes by discussing the concept of scale and the use of deep neural networks in algorithms.
10 Math Concepts for Programmers
People often say you don't need to know any math to program a computer, and that's truthy. However, any sufficiently advanced technology is from magic, but magic isn't real. Math explains it all. Developers often avoid learning math because it looks scary, but it actually makes complicated magic like computer graphics and neural networks easier to understand. And not just that, but it unlocks the secrets of the entire physical universe. There's a few abstract math concepts for programmers that you just can't ignore, and understanding them will make you think more like a true engineer. I'm no math genius. In fact, I'm the opposite, which makes me uniquely qualified to teach 10 essential math concepts using memes and other visual aids that almost anybody can understand. The first person who survives until the end cracks the code will win this one of a kind Balenciaga Fireship Hoodie. Let's jump right into topic number 1, Boolean algebra, which is used almost every time you write code. A boolean is a binary variable that can have two possible values, true or false. Now there are 3 operators that you can use to work with them, and, or, and not, or conjunction, disjunction, and negation if you wanna be fancy. Imagine you're trying to get a girlfriend. We can use the boolean variables of rich and handsome to describe you. If you're both rich and handsome, you'll definitely get a girlfriend. But if you're not rich and not handsome, you'll have to pay for an OnlyFans girlfriend. If you're rich or handsome, you can still get a girlfriend, but your selection is more limited. We can represent this logic in code with things like if statements, but we can also do it with Venn diagrams like you've been doing since grade school. And you can also create truth tables like this one here, which comes in handy in zombie apocalypse type situations. But that brings us to concept 2, numeral systems like base 2. Throughout history, humans have come up with all kinds of clever ways to count things, but almost all of them use base 10 like the 10 fingers on your hands. Distance. Like in the number 423, the 4 is in the 100s place, which represents 4 times 100. The 2 is in the tens place or 2 times 10. Then the final number is multiplied by 1, but computers work off of a base two numeral system. In base 2, things work the exact same way, but because we only have 2 symbols to work with, each place is multiplied by 2, like 248163264128 and so on. Now that you understand that, You also understand how other bases work, like base 16 or hexadecimal, which uses the digits 0 through 9 along with a through f, and is commonly used to represent binary values in a more concise way because each hexadecimal digit can translate into 4 bits. And you also have base 64, which introduces even more letters and symbols to encode binary values, allowing developers to represent binary data like an image as a string of text. While computers use base 2 under the hood. They still need to represent base ten numbers for humans, and the most common way to do that is with floating point numbers. Go ahead and execute 0.1 +0.2 in your favorite programming language. The result should be 0.300004. How could a computer make such a silly mistake? Well, in science, numbers can get very big when talking about space and very small when talking about things like atoms. We don't write these numbers out completely and instead use scientific notation, where an exponent raises it to an approximate value, making the number appear far more concise. Computers use a similar approach with floating point numbers because they only have a limited amount space, either 32 bits for single precision or 64 for double precision, which is the default in languages like Python and JavaScript. It's called a floating point because there's no fixed number of digits or after the decimal point, allowing developers to make a trade off between range and precision. Some numbers like 0.01 can't be represented perfectly as a binary floating point, which is the reason we get those tiny rounding errors. Now that you know how numbers work, we can start talking about logarithmic functions, which you might remember from algebra class. To them. Think of an actual log. The log starts at 16 feet, then we saw it in half over and over again until we reach a length of 2. Notice how when we try to draw a line through it, it's not straight, but rather it curves gradually. In computer science, this is how many algorithms work like binary search. What's interesting though is that if we know how many times we cut the log, raised 2 to the power of that value, in this case 4, to get the original length of the log. That's called exponentiation, and logarithm is the exact opposite. Imagine we don't know the exponent, We only know the original length and want to figure out how many times we'd have to cut the log to get a length of 2. We could calculate that with a base 2 log on the original length, returning value of 4. When it's base 2, it's called a binary logarithm. However, in math, it's more common to use base 10, which is called the common logarithm. That'll come in handy, but now let's shift gears to set theory. A set is just an unordered collection of unique values. The best example is a relational database where each table is a set of unique rows. These tables can be joined together in a variety of different ways based on set theory. Like to select records that match on both tables, you do an inner join, which is called an intersection in set theory. Or to grab all matching records from both tables, you do a full outer join, which is a union in set theory. When doing left and right joins, these concepts are combined, like by combining an intersection with the difference between the two sets. Now one thing that's important to notice at this point is that we're talking about structures that have a finite number of elements, which falls under the umbrella of discrete math, as opposed to continuous math, like geometry and calculus, that deal with real numbers and approximations. And that brings us to our next discrete topic combinatorics. Simply put, this is all about counting things, especially when combining sets into combinations or permutations. Like, if you have an app like Tinder, you might need to count all the possible combinations of matches as part of a more complex algorithm that figures out what the end user, or maybe you're building a globally distributed database and need to figure out how many database partitions you'll need around the world. Ultimately, it's all about understanding how patterns can emerge. What you're looking at here is the formula for the Fibonacci sequence. A great exercise is to write a function that generates it. Congrats, bro. You just did combinatorics and unlock the secrets of the universe. Engineers at Google use the same kind of logic to render tiles on tools like Google Maps, and the gods use this pattern all over the place in nature. Combinatorics is closely related to graph theory. A graph has two basic parts, nodes or vertices and edges that connect them together. Like, a person might be a node, and an edge might be a relationship that connects them together. Like you love your mom and your mom loves you back. This is an undirected graph because the relationship goes both ways. However, you might also love your OnlyFans girlfriend, but this would be a directed graph because that relationship only goes one way. Edges can also be weighted, meaning one relationship is more important than the If a node can traverse back to itself, it's called cyclic. Otherwise, it's known as acyclic. As a programmer, you'll often need to build graphs from the ground up, but more importantly, know how to traverse them, like when using Dijkstra's algorithm to find the most efficient way to navigate through traffic. But before you start writing graph traversal algorithms, you should know a little bit about complexity theory, which can tell us in theory how much time and memory an algorithm should use. We use big o notation to express complexity, and when talking about time, the input represents the number of steps it will take to complete a task. Like, if we read a single element from an array, that would give us o of 1 or constant time, which is extremely fast and simple. If we need to loop over an array, that would give us o of n, where n is the length of the array. But if for each iteration in that loop, we loop over the same array again, that would give us o of n squared, which would be far less efficient. However, more sophisticated algorithms like binary search cut the search area in half after each iteration, providing us with logarithmic time. Understanding how to measure complexity is essential for technical interviews and is just a good thing to think about in general. But now let's move away from discrete math and talk about statistics, which is crucial if you want to do anything with artificial intelligence because machine learning is kind of just way of doing statistics. Like, when you type in a chat gpt, it generates a response based on the probability that it fits the prompt provided by the user. At the very least you should understand mean, median, and mode, and how standard deviation indicates how close values in a set are correlated to the mean. There's a ton to learn beyond that, but what I found especially useful is the difference between linear regression and logistic regression. In a linear regression, the goal is to predict a continuous value, like the amount of money you'll lose after buying a stock. The relationship between the input and output variable is linear, and the idea is to find a line that best fits the dataset. However, logistic regression is used for an entirely different set of problems like classification, maybe an app that predicts if an image is a hot dog or not a hot dog. In this case, the relationship is not linear, but rather a sigmoid function, which might predict the probability that a boolean variable is true or false. And that brings us to our final and most difficult topic, linear algebra, which comes into play in things like computer graphics and deep neural networks. To comprehend it, you'll need to understand 3 weird words. Scalar is a single numeric value. A vector is a list of numbers like a 1 dimensional array. And finally, a matrix is like a grid or 2 dimensional array that contains rows and columns of numeric values. What's cool is that vectors can represent points and directions in a 3 space, while matrices can represent transformations that happen to these vectors. When you move a player around in a video game, the lighting and shadows and the graphics change magically, but it's not magic. It's linear algebra that's being distributed on your GPU. Imagine you have a 2 d vector that's at point 2x3y. It represents a single point in an image. We can perform linear transformations here like scaling, translation, rotation, shear, and so on. Let's imagine we now want to scale the point to a value of 4 x 6 y. We can represent the scaling factors in a matrix, then represent the point as a column vector. And now we can use matrix multiplication to scale the point to its target location. Operations like this are also essential in things like cryptography, such as RSA encryption and are also essential in deep neural networks, which use vectors to represent features, then use matrix multiplication to propagate values between nodes in the network. The underlying math is surprisingly simple, but requires a massive amount of computing power to handle the staggering amount of data required. As you can see now, math is actually not that complicated, and the more you study it, the more the computer will reveal its magic tricks. Thanks for watching, and I will see you in the next one.
The speaker explains the concept of mathematics and the use of base 2, fixed precision numbers, and analytics. They also discuss the concept of structures with a finite number of elements and the use of linear and logistic regression in algorithms. The speaker emphasizes the importance of understanding complexity in machine learning and analytics for technical interviews and concludes by discussing the concept of scale and the use of deep neural networks in algorithms.