Programming Terms: Memoization

Поділитися
Вставка
  • Опубліковано 3 січ 2025

КОМЕНТАРІ • 92

  • @myles199
    @myles199 6 років тому +116

    My lecturer spent 2 hours trying to explain this to us didn't understand a thing. You done it in 5 and it makes total sense. THANKS!!

    • @TrumanBurbonk
      @TrumanBurbonk 5 років тому +1

      Could you explain mi this:
      if ef_cache changes because result changes then how can old num be recognized? Is ef_cache storing those results without overrunning one with the nex one?

    • @Girish4944
      @Girish4944 4 роки тому +1

      @@TrumanBurbonk yes ef_cache is storing those results without overrunning with the next one.

  • @monk_
    @monk_ 5 років тому +109

    Every time I hear "Memoization" I imagine someone saying "Memorization" in a baby voice.

    • @Goozeeeee
      @Goozeeeee 3 роки тому +3

      I'm never going to look at this the same way again

  • @Poser_Metal_Records
    @Poser_Metal_Records 9 років тому +28

    Awesome. Short, simple, and straight to the point. Thank you.

  • @팍준하
    @팍준하 4 роки тому +29

    Summary:
    Memoization refers to the mechanism that makes a function not having to compute the output using an input, when the function has been executed using the same input before. This is possible because the computer memorizes the input:output pair.
    This tool can be demonstrated in python using an if statement and a dictionary outside the function.

  • @corbettknoff5123
    @corbettknoff5123 4 роки тому

    Whenever I don't understand something and I find a Corey Schafer video I'm always relieved. I know I'm finally going to understand it.

  • @amr3162
    @amr3162 7 років тому +8

    Dude you're literally god, I just finished your first class functions, closure, and decorators videos and while watching this I realized how useful it would be to implement memoization using a decorator.

    • @yacinegaci6402
      @yacinegaci6402 7 років тому

      nice thought, it would really show how decorators could be robust and useful

  • @63montywilliams50
    @63montywilliams50 2 роки тому

    been rockin with you for a while now, good content mr chaffer!

  • @ayizeakono8492
    @ayizeakono8492 6 років тому +1

    All your videos are well organized and delivered....thanks so much for sharing!!!!

  • @devworks8787
    @devworks8787 Рік тому

    This is the proper video for memoization explained for Python while most use the Fibonacci example

  • @monireachtang712
    @monireachtang712 Рік тому

    Very clear and easy to understand! Thank you for sharing.

  • @anon-sl4vp
    @anon-sl4vp 6 років тому +3

    another brilliant video :) love learning about programming terms and such... if you could do an advanced playlist of the terms maybe in more detail/other ones would be great :) love learning concepts which like you say are not syntax/prog_lang specific.. act learning the blueprints so to speak of how and why it works

  • @roy6787
    @roy6787 6 років тому +2

    Holy Moly! Thanks for that, bro. Really helps me optimized my program!

  • @maxim9280
    @maxim9280 5 років тому +1

    At last a clear cut explanation.

  • @theartist8835
    @theartist8835 5 років тому

    A very beautiful playlist ❤️ do more of these please. They're so useful

  • @darshanmm9
    @darshanmm9 7 років тому +4

    Hi Corey
    I become your fan!
    i never seen anyone teach with such clearity on youtube😊👍

    • @petarkolev6928
      @petarkolev6928 6 років тому

      Yes, he does it very well! But checkout FunFunFunction channel as well if you are in to JavaScript ofc :)

  • @kesh4505
    @kesh4505 4 роки тому +3

    best explanation !

  • @robinfrancis9914
    @robinfrancis9914 8 років тому +4

    You are a great teacher!!

  • @techfornoobs4241
    @techfornoobs4241 7 років тому +3

    This is an awesome explanation. thank you so much!

  • @lisandrofilloy5126
    @lisandrofilloy5126 4 роки тому

    Great work Corey!

  • @krishnar9932
    @krishnar9932 5 років тому +1

    Simplified explanation. Thanks

  • @wouterspelt
    @wouterspelt 3 роки тому

    Clear explanation! Thanks.

  • @navjotmannan7303
    @navjotmannan7303 5 років тому +1

    Awesome explanation!!

  • @davidm.johnston8994
    @davidm.johnston8994 7 років тому

    I love you man, your videos are just so useful and easy to understand. Thanks

  • @captainmash-h8h
    @captainmash-h8h 4 роки тому

    very clear and clean explanation, thanks!!!

  • @anim3197
    @anim3197 3 роки тому

    Very well explained. Thank you!

  • @jonathanwhite2715
    @jonathanwhite2715 5 років тому +1

    Thanks. Easy to understand

  • @charlesokoyoh
    @charlesokoyoh 5 років тому +1

    Thank you Corey

  • @sairajdas6692
    @sairajdas6692 6 років тому +1

    Excellent video

  • @hustels
    @hustels 8 років тому +5

    Amazing tutorials.

  • @samwilliams4024
    @samwilliams4024 5 років тому +3

    Huge fan of your videos Corey!
    The functools.lru_cache decorator is also a great way to implement memoization on functions.

  • @smallblueflower
    @smallblueflower 7 років тому

    You're videos are great! Thank you!

  • @dipankararora2633
    @dipankararora2633 5 років тому +1

    your videos are too good.

  • @Leonardo-jv1ls
    @Leonardo-jv1ls 3 роки тому

    When I have a doubt about anything in this world, i go to youtube and write "corey schafer +anything". If not found, i quit of learning it.

  • @futurestar1000
    @futurestar1000 8 років тому

    such smooth explanation corey \/

  • @hubertcombomarketing2693
    @hubertcombomarketing2693 4 роки тому

    Good as always. Thanks.

  • @MaxS-v7x
    @MaxS-v7x 7 років тому

    Thank you for your work, perfectly explain!

  • @luizfelipels7
    @luizfelipels7 3 роки тому

    Such a fancy name for a simple idea.

  • @abuyusufansari6620
    @abuyusufansari6620 7 років тому

    Thank you for this nice explanation.

  • @wartem
    @wartem 2 роки тому

    This is brilliant

  • @TheTruthFadeswithTime28
    @TheTruthFadeswithTime28 6 років тому +1

    Can you do a video on recursion ?

  • @quinnwang6929
    @quinnwang6929 3 роки тому

    Great presentation. Is it okay to use "list" instead of "dictionary" in the ef_cache? Thx.

  • @Lahiru_Udana
    @Lahiru_Udana 5 років тому

    Thanks for the great video

  • @ryan-tabar
    @ryan-tabar 2 роки тому +10

    # You can turn the process into a decorator so you can add it to any function
    def memoization(original_function):
    cache = {}
    def inner_function(arg):
    if arg in cache:
    print(f"Result was retrieved from cache.")
    return cache[arg]
    else:
    print(f"Memoizing result of function {original_function.__name__}({arg}).")
    cache[arg] = original_function(arg)
    return cache[arg]
    return inner_function
    @memoization
    def square(number):
    return number ** 2

  • @maxim9280
    @maxim9280 5 років тому +1

    But this only seems useful when you've multiple calls of the same function with the same arguments. My point is, what could this possibly be for in a program?
    In many applications a function is called as many times as the program itself is called. But the cache gets cleared anyway. Could this method be used here?

    • @boggeshzahim3713
      @boggeshzahim3713 5 років тому

      I'm sure it has uses outside the classroom... somewhere

    • @obed818
      @obed818 2 роки тому

      this comment is old but ill add my touch, this exemple is the best by mcoding and you will maybe appreciate the decorator trick, in recursive call it can get useful ua-cam.com/video/DnKxKFXB4NQ/v-deo.html

  • @snoopyjc
    @snoopyjc 5 років тому +1

    How are you using “print” without () ?

    • @yashrajvanshi17
      @yashrajvanshi17 5 років тому +4

      That program was written in Python 2.X version not in Python 3

  • @antoniosaqueton3293
    @antoniosaqueton3293 3 роки тому

    Hope you can come up with tutorials on data structures or at the least, recursion. Please help a brother out!

  • @ziqb
    @ziqb 4 роки тому +5

    All my life, I had been calling it caching ..

  • @pythoninnovate2428
    @pythoninnovate2428 8 років тому

    Like your videos on Python ...
    Quick query on this video:
    Im a beginner so a very simple query though:
    How did you get the time of the overall execution of the program, i mean 4.0s or 2.0s in this video? Any inputs on how to get it in 'pycharm' will be helpful.

    • @DarkOceanShark
      @DarkOceanShark 3 роки тому

      Hello, are you able to do it now (5 years)?

  • @kavitatoragal2911
    @kavitatoragal2911 4 роки тому

    How do you show the time spent [Finished in _s]? Is it some configuration?

    • @vasudev16180
      @vasudev16180 4 роки тому

      It will show you automatically In the sublime text editor

  • @hsabrey
    @hsabrey 5 років тому

    how to show that command says [Finished in 4.0s], i did not find it in vsCode, appreciate your help.

  • @stevendye249
    @stevendye249 6 років тому

    Why don't we need an else statement after the if statement in expensive_func?

    • @coreyms
      @coreyms  6 років тому

      Because if it runs the code in the "if" statement then it will just immediately return... so you don't need the else statement because the code after the "if" won't be run anyways if the conditional is met. Hope that makes sense.

    • @sodapopinski9922
      @sodapopinski9922 6 років тому

      then why do we need else statements. if the program meets the conditional it breaks after the return, if not it runs the rest of the code

    • @ultiumlabs4899
      @ultiumlabs4899 6 років тому

      it is actually Corey's style. you could use different style and use else statement to get the same result. in the if block: just assign the result to result variable.
      if num in ef_cache:
      result = ef_cache[num]
      else:
      print('')
      time.sleep()
      ef_cache[num] = num*num
      result = num*num
      return result

  • @Usammityduzntafraidofanythin
    @Usammityduzntafraidofanythin 6 років тому

    Shouldn't the block after the if in the expensive function still execute after the if executed, even if there is a value put in that matches what's in dictionary?

  • @chrishau6178
    @chrishau6178 7 років тому

    Will the caching still work if you import the function into a separate program?

    • @coreyms
      @coreyms  7 років тому

      Yes, that should still work.

  • @augiblutz2852
    @augiblutz2852 2 роки тому

    well done

  • @abinash138
    @abinash138 7 років тому

    what is the use of sleep in this program

    • @coreyms
      @coreyms  7 років тому +1

      Sleep just pauses the execution for a bit so that we can simulate the time it might take to compute a more intensive function

  • @khireddinebelkhiri725
    @khireddinebelkhiri725 5 років тому +1

    thank you thank you thank you

  • @poorna685
    @poorna685 4 роки тому +1

    i thought he would explain about lru_cache

  • @jean-michelcid9594
    @jean-michelcid9594 4 роки тому +1

    amazing!!!!

  • @bernoulli9047
    @bernoulli9047 5 років тому

    If you're looking to make an intermediate series of videos, memoization using Python 3's functools.lru_cache would be pretty cool.

  • @VictorSantos-yb8ir
    @VictorSantos-yb8ir 3 роки тому

    Thanks!

    • @obed818
      @obed818 2 роки тому +1

      Hello if you plan to use it i suggest you to check this video more up to date 👍 ua-cam.com/video/DnKxKFXB4NQ/v-deo.html

  • @rohanpednekar8074
    @rohanpednekar8074 4 роки тому

    Great !

  • @ashishkumarnath1259
    @ashishkumarnath1259 4 роки тому

    You are god!!!!, thank you so much!

  • @MrBrainOwl
    @MrBrainOwl 7 років тому

    Perfect!!!

  • @mymantra4
    @mymantra4 3 роки тому

    Plz zoom the code

  • @johnc7436
    @johnc7436 4 роки тому

    Good

  • @adrianmoscovciuc4297
    @adrianmoscovciuc4297 4 роки тому

    Nice video Corey, thx for teaching us all this info. For all of you that need and example of the memoization used, you can reffer to the Socratica video on fibonacci sequence: ua-cam.com/video/Qk0zUZW-U_M/v-deo.html , with those two videos you will be able to understand better the concept.

  • @jiernade4585
    @jiernade4585 Рік тому

    Last minute assignment anyone? xd

  • @connormichalec
    @connormichalec 4 роки тому

    I came hear to learn how to pronounce the word

  • @pipboy214
    @pipboy214 4 роки тому

    Maybe your video is good for a first grasp of the term, and you could say thats the point, but memoization is also a technique that doesn't need an external data structure to work, i sugest you to read and maybe talk about it, cause nobody wants dirty globals or spaghetti oriented programming, when You can implement a memoized pure function.

  • @_slier
    @_slier 4 роки тому +1

    Im just gonna save ur time..Memoization is purely caching...

  • @karimmoradi2003
    @karimmoradi2003 Рік тому

    As always, very nice explanation Corey, Thanks. What about using functools.cache decorator?