Best Way to Learn Python in 2020 : Episode 5

 If you reached this episode, give yourself a pat on the shoulder.

Because by now, you have the skills that enable you to solve a wide variety of problems.

However, something is missing.

You are still not seasoned enough at writing efficient code.

What do I mean by that?

For example, you don’t know how to modify your code to make it run faster. You can’t even analyze why it is slow in the first place.

This is normal.

The knowledge you have learned so far in the previous levels are not enough for you to have a solid understanding of what performance really is, and how to modify your existing code to make it run faster.

Don’t believe me? Look at this simple code that calculates the nth Fibonacci number.

def fib(n):
    if n < 2:
        return n
    return fib(n-2) + fib(n-1)

print(fib(100))

The code looks simple enough and very straightforward, right?

Try using this code to calculate fib(100) [SPOILER ALERT: it will take an extremely long time]

Now let’s make a simple modification to the code.

def fib(n, d):
    if n < 2:
        return n
    if n not in d:
        d[n] = fib(n-2, d) + fib(n-1, d)
    return d[n]

print(fib(100, {}))

This time all it took was a few milliseconds and you will get the answer, which is 354224848179261915075 just in case you’re wondering 🙂

I used what’s called dynamic programming to solve this problem and make it run astronomically faster.

Well, I hope you are convinced by now that you should learn data structures and algorithms.

The skills that you are going to learn at this level are some of the major differentiators between average coders and solid programmers.

You will need to learn about linked liststreesstacksqueuesgraphshash tablesrecursiondynamic programming, searching and sorting algorithms, etc…

Once you master these concepts, you are steps away from getting a software engineering job at any tech company of your choice.

I really mean it!

Hope u guys enjoyed this episode!!

Comments

Popular posts from this blog

Best Way to Learn Python in 2020 : Episode 4

Best Way to Learn Flutter (2020 Step-by-Step Guide) : Episode 2

Best Way to Learn Python in 2020 : Episode 2