To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
Here is a fun little CS tidbit for you,
Take the following flow chart. This is something that you might see in any normal programming project.
If you had to create code for it, you would likely go if (i==j)…
It’s only normal to expect your assembler will do the same when changing your code from your High-Level Language of choice to the Machine Code.
However, that’s not what happens. The Assembly code for this flow chart will look like this-
To those of you that can’t read assembly focus on the first line. What is bne? It means ‘branch not equal’. This would translate into if (i!=j). Essentially, the assembler has flipped the conditions and is checking for inequality. Why does this happen?
Simply put i==j is slow. Checking if i!=j is much more efficient. Confused by why?
Think of how equality is checked. We have to compare two numbers bit by bit (these numbers are stored in binary. Check out last week’s Math Monday for more deets). Checking 2 64-bit ints will need 64 checks. To be equal, we need all 64 to be identical. To check for inequality, you just need to find one set that doesn’t align. Thus you can stop early.
Enforcing a rule like this also simplifies compiler design. When translating high-level to low-level code, having a rule like this streamlines this process. You will see this a lot in System/Compiler Design. Enforcing a few rules on the kind of inputs accepted or process that run can simplify decisions significantly. For a deeper discussion of this, check out this Stack Overflow post discussing why we use bne instead of beq (checking for equality).
You don’t need to worry about changing your if statements. Your compilers will do this for you automatically. However, this approach will be extremely useful as you start creating your own data structures and types. When writing comparators it will be useful to filter through areas and check for inequality. And when it comes to higher level design, enforcing some constraints to simplify your process will go a long way.
I created Technology Interviews Made Simple using new techniques discovered through tutoring multiple people into top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on the Leetcode grind. I have a 100% satisfaction policy, so you can try it out at no risk to you. You can read the FAQs and find out more here. Use the button below to get 20% off for upto a whole year.
Before proceeding, if you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
I see you living the dream.
Go kill all and Stay Woke,
Devansh <3
To make sure you get the most out of Math Mondays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75