Programming Terms: Memoization

Поделиться
HTML-код
  • Опубликовано: 18 янв 2025

Комментарии • 92

  • @monk_
    @monk_ 5 лет назад +110

    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

  • @myles199
    @myles199 6 лет назад +117

    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 5 лет назад +1

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

  • @Poser_Metal_Records
    @Poser_Metal_Records 9 лет назад +28

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

  • @팍준하
    @팍준하 4 года назад +30

    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

  • @ayizeakono8492
    @ayizeakono8492 6 лет назад +1

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

  • @63montywilliams50
    @63montywilliams50 2 года назад

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

  • @monireachtang712
    @monireachtang712 Год назад

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

  • @roy6787
    @roy6787 6 лет назад +2

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

  • @techfornoobs4241
    @techfornoobs4241 7 лет назад +3

    This is an awesome explanation. thank you so much!

  • @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

  • @devworks8787
    @devworks8787 Год назад

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

  • @krishnar9932
    @krishnar9932 5 лет назад +1

    Simplified explanation. Thanks

  • @theartist8835
    @theartist8835 5 лет назад

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

  • @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!!!

  • @maxim9280
    @maxim9280 5 лет назад +1

    At last a clear cut explanation.

  • @anim3197
    @anim3197 3 года назад

    Very well explained. Thank you!

  • @jonathanwhite2715
    @jonathanwhite2715 5 лет назад +1

    Thanks. Easy to understand

  • @wouterspelt
    @wouterspelt 3 года назад

    Clear explanation! Thanks.

  • @robinfrancis9914
    @robinfrancis9914 8 лет назад +4

    You are a great teacher!!

  • @kesh4505
    @kesh4505 4 года назад +3

    best explanation !

  • @charlesokoyoh
    @charlesokoyoh 5 лет назад +1

    Thank you Corey

  • @navjotmannan7303
    @navjotmannan7303 5 лет назад +1

    Awesome explanation!!

  • @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.

  • @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 :)

  • @MaxS-v7x
    @MaxS-v7x 7 лет назад

    Thank you for your work, perfectly explain!

  • @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

  • @smallblueflower
    @smallblueflower 7 лет назад

    You're videos are great! Thank you!

  • @hustels
    @hustels 8 лет назад +5

    Amazing tutorials.

  • @abuyusufansari6620
    @abuyusufansari6620 7 лет назад

    Thank you for this nice explanation.

  • @lisandrofilloy5126
    @lisandrofilloy5126 4 года назад

    Great work Corey!

  • @sairajdas6692
    @sairajdas6692 6 лет назад +1

    Excellent video

  • @futurestar1000
    @futurestar1000 8 лет назад

    such smooth explanation corey \/

  • @dipankararora2633
    @dipankararora2633 5 лет назад +1

    your videos are too good.

  • @hubertcombomarketing2693
    @hubertcombomarketing2693 4 года назад

    Good as always. Thanks.

  • @TheTruthFadeswithTime28
    @TheTruthFadeswithTime28 6 лет назад +1

    Can you do a video on recursion ?

  • @Lahiru_Udana
    @Lahiru_Udana 5 лет назад

    Thanks for the great video

  • @quinnwang6929
    @quinnwang6929 3 года назад

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

  • @wartem
    @wartem 2 года назад

    This is brilliant

  • @khireddinebelkhiri725
    @khireddinebelkhiri725 5 лет назад +1

    thank you thank you thank you

  • @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.

  • @luizfelipels7
    @luizfelipels7 3 года назад

    Such a fancy name for a simple idea.

  • @antoniosaqueton3293
    @antoniosaqueton3293 3 года назад

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

  • @augiblutz2852
    @augiblutz2852 2 года назад

    well done

  • @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 ruclips.net/video/DnKxKFXB4NQ/видео.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

  • @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 👍 ruclips.net/video/DnKxKFXB4NQ/видео.html

  • @hsabrey
    @hsabrey 5 лет назад

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

  • @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.

  • @ashishkumarnath1259
    @ashishkumarnath1259 4 года назад

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

  • @jean-michelcid9594
    @jean-michelcid9594 4 года назад +1

    amazing!!!!

  • @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

  • @poorna685
    @poorna685 4 года назад +1

    i thought he would explain about lru_cache

  • @ziqb
    @ziqb 4 года назад +5

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

  • @rohanpednekar8074
    @rohanpednekar8074 4 года назад

    Great !

  • @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.

  • @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?

  • @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

  • @johnc7436
    @johnc7436 4 года назад

    Good

  • @MrBrainOwl
    @MrBrainOwl 7 лет назад

    Perfect!!!

  • @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

  • @mymantra4
    @mymantra4 3 года назад

    Plz zoom the code

  • @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: ruclips.net/video/Qk0zUZW-U_M/видео.html , with those two videos you will be able to understand better the concept.

  • @pipboy214
    @pipboy214 5 лет назад

    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.

  • @jiernade4585
    @jiernade4585 Год назад

    Last minute assignment anyone? xd

  • @connormichalec
    @connormichalec 4 года назад

    I came hear to learn how to pronounce the word

  • @_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?