Hook

Their other posts in the index, biggest breakout first.
Most programmers have a degree in engineering or science. Do you know why? There are two main reasons for this. One, generally speaking, engineers can think logically. Two, engineers are good at math. One of the major reasons I was able to get a job at Google without a computer science degree is because I'm above average at math. Now, I cannot teach you all the math I know in one short video. You anyway don't need most of it to become a programmer. Let me do this. I'll share five essential math skills that will get you 80% there. The rest of the 20% you can learn on the go as you encounter new problems. But why do programmers even need math? Imagine that you are a software engineer at Google and you are given a critical problem to solve. Many Google users are not able to access the website because of an overloaded server. This problem is getting worse with every passing minute. Just because the client side is configured to do an automatic retry after one second for every failed call. You talk to a senior engineer on the team and she recommends using exponential backup for re-traces. What does exponential mean? You ask her. She points you to the documentation. If your math skills are not good, it might take you a long time to understand and implement exponential piece of the algorithm even after reading the documentation. In the meantime the entire internet traffic will see a huge drop because for many people no Google means no internet. Now if this example doesn't convince you here is an even more important reason to learn math. Most tech companies conduct coding interviews to see if you are a good fit for the role and whether you like it or not they ask algorithm style questions in these interviews. At the end of the interview the interviewer usually asks you time and space complexity of your solution. In order to answer these questions and actually get job. You need to know some basic math concepts. Many people who come from a non-CS and non-engineering backgrounds have hard time answering these questions. That's why I have chosen the top five math skills for today keeping these interviews in mind. Now I know that there's a scalable number of you who pretty much hate coding interviews and don't want to go through them and I completely respect your position. But for the vast majority of us we don't have the luxury to give up on our dreams just because we don't like one step of the process. This video is for those people. Let's learn some math. To learn the first concept We need to start with an exercise. Here is a piece of code that contains a for loop tested inside another for loop. What is the time complexity of this code? In other words, how many times will this code print hello world for any arbitrary value of n? This video is going to be interactive. So you can pause the video and leave the answer in the comments. If your answer is order n square or n square times, then you are going to benefit a lot from what I am about to tell you. Most of the people who answer n square do it because they confuse the code I gave you with this other piece of code. This see an n square for loop inside another and immediately conclude N square which is the wrong answer in this case to understand why that is let's think from the first principles looking at the code it's obvious that the outside for loop runs end times each time this outside loop runs we go inside and run this nested loop k times we don't know what that k is at this time but we'll find out shortly so in total we print k into hello world statements now if you look at this other easier and more popular piece of code the internal loop also runs end times but that's not the case in the code I gave you what I want you to take away from this is that whenever you have A that happens x times and every time a happens b happens y times b will happen total of x into y times. Now to know the value of k in the last exercise we need to know the second concept. So here is a question for you. You are given a stick that is 32 meters in length. You break it into two half. You throw the right piece away and you break the left piece into two half again. You throw away the right half and keep breaking the left piece until you have a stick of length one meter left. How many times did you break the stick in total? You can pause the video and leave the answer below. If you answer five then you are right. Here is an interesting observation about the answer. If you take two which is the total number of pieces you break the stick into every time and if you take five which is your final answer and you multiply two to itself five times you get 32 which is the original length of the stick. In other words 2 to the power 5 is 32 whenever you have an equation like this 5 is called the logarithm of 32. Technically speaking it's logarithm to the base two but in computer science people usually think in terms of logarithm to the base two. So we can just call it logarithmic or log here for our purpose. But it's important to know that in math people usually mean logarithmic to the base 10 when they say log I recommend that you read a little bit more about logarithmic on your own. Anyway in the generic case if two to the power of x is n then x is called the logarithmic of n. So in the stick example you broke the stick a total of log 32 times which is five going back to the example with two four loops if you look closely at the internal loop it does exactly the opposite of the stick breaking example. We start with the stick of length one when you do J is equal to J multiply by two or in other words you double the length you are bringing a stick of the same length from somewhere and you are attaching it to the original stick and you keep doing it until you reach the length in. So how many times do you have to double the length of the stick this way until you reach the length of n. Looking at the stick example I gave you it's going to be log n and that's the key we were looking for. So total number of times you print hello world in this case is n into k which is n log n. If you have some experience with algorithms I'm sure you have already seen that stick breaking example is very similar to binary search algorithm. algorithm also appears in some other algorithms like sorting and some heop related problems. Before I can explain what exponential means and exponential back off we have to understand this third concept of the day. For that I have another question for you. How many three digit numbers can you make by using digits one two and three given that you can use each digit only once. You can pause the video and leave the answer in the comments. If you answered six then you are right. But what if I ask the same question for nine digit numbers using digits one to nine without repetition. To answer this question you need to know what a factorial is. Let's understand factorial using the three digit problem. We can call the first digit A second one B and the third one C. Let's pick the first digit of this number. For that we can use any digit from one two and three. So we have three options here. Let's say we pick two for the first digit. For the second digit we only have two options left because we can use one digit only once. Let's say we pick three for the second digit. Now for the last digit, you only have one option which is one. Can you see that we can use the first concept we learn today here. So the total three digit numbers would be a multiplication of three, two and one which is six. For the nine digit case using all the digits from one to nine, the answer would be the multiplication of all the numbers from one to nine. And this multiplication is called nine factorial and it written like this. factorial is nothing but the multiplication of all the numbers from one to that number including the number itself. factorial appears in many algorithms like finding subsets of a set and permutation of numbers etc. Now that we have that out of the way let's talk about the fourth concept which is exponents and for that we need to go back to the three digit numbers example let me change the question a little bit for you how many three digit numbers can you make using the digits one two and three if you can use a digit more than once I would love to see your answer in the comments if you go back to the example I gave you for you will see that now we have three options for a B and C and that's why total three digit numbers would be three into three into three which is three to the power three. And this is called exponentiation or exponential. Let's try to understand exponential backup based on what we know now. In the exponential back of algorithm you will do the first try for a failed request after X seconds. If the request fails again you will increase the wait time for the wait time again. and you keep doing it. If you look closely, the wait time for retrying the field request is increasing exponentially here. Hence the name exponential backup. One of the main characteristics of something that is exponential is that it increases or decreases really fast. For example, the spread of COVID was exponential because one person could let's say infect three people and each of those three will infect three more and so on. exponential growth is a powerful concept for life in general and it can be life changing for new programmers. That's because in the beginning most programmers have the snacking that they are not growing fast enough. Many get demotivated and give up as a result. But here is a graph showing the power of exponentiation from the book atomic habits by James clear. If you just improve 1% each day for 365 days you will be 38 times better at the end of the year and if you build bad habits and become just 1% worse each day you will lose 97% of what you have today in one year. This exponentiation in action for you my friend. Another concept you need to know about is modulus for positive numbers modulus is the same as what you would normally call remainder in the division of two numbers. modulus operator is written as a percentage sign. So 27 mod 5 is two which is the same as the remainder when you divide 27 by 5. For negative numbers there is a small difference between mod and remainder which I recommend you read up yourself. Some popular interview problems that use mod are find greatest common divisor of two numbers and fishes bus. So now you know the math you need to become a programmer. Next you need a simple well defined step by step back to learn programming. If you want to know the path I recommend watch this video. My name is and I'll see you in the next one.