Programming Terms: Memoization

  Рет қаралды 73,265

Corey Schafer

Corey Schafer

Күн бұрын

Пікірлер: 92
@myles199
@myles199 6 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@TrumanBurbonk yes ef_cache is storing those results without overrunning with the next one.
@monk_
@monk_ 5 жыл бұрын
Every time I hear "Memoization" I imagine someone saying "Memorization" in a baby voice.
@Goozeeeee
@Goozeeeee 3 жыл бұрын
I'm never going to look at this the same way again
@Poser_Metal_Records
@Poser_Metal_Records 9 жыл бұрын
Awesome. Short, simple, and straight to the point. Thank you.
@justgivemethetruth
@justgivemethetruth 7 жыл бұрын
Yeah, Wikipedia is great
@팍준하
@팍준하 4 жыл бұрын
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.
@thinhnguyenvan7003
@thinhnguyenvan7003 4 жыл бұрын
Nice
@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 жыл бұрын
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 жыл бұрын
All your videos are well organized and delivered....thanks so much for sharing!!!!
@anon-sl4vp
@anon-sl4vp 6 жыл бұрын
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
@monireachtang712
@monireachtang712 Жыл бұрын
Very clear and easy to understand! Thank you for sharing.
@devworks8787
@devworks8787 Жыл бұрын
This is the proper video for memoization explained for Python while most use the Fibonacci example
@roy6787
@roy6787 6 жыл бұрын
Holy Moly! Thanks for that, bro. Really helps me optimized my program!
@theartist8835
@theartist8835 5 жыл бұрын
A very beautiful playlist ❤️ do more of these please. They're so useful
@techfornoobs4241
@techfornoobs4241 7 жыл бұрын
This is an awesome explanation. thank you so much!
@davidm.johnston8994
@davidm.johnston8994 7 жыл бұрын
I love you man, your videos are just so useful and easy to understand. Thanks
@robinfrancis9914
@robinfrancis9914 8 жыл бұрын
You are a great teacher!!
@darshanmm9
@darshanmm9 7 жыл бұрын
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 :)
@maxim9280
@maxim9280 5 жыл бұрын
At last a clear cut explanation.
@kesh4505
@kesh4505 4 жыл бұрын
best explanation !
@lisandrofilloy5126
@lisandrofilloy5126 4 жыл бұрын
Great work Corey!
@wouterspelt
@wouterspelt 3 жыл бұрын
Clear explanation! Thanks.
@krishnar9932
@krishnar9932 5 жыл бұрын
Simplified explanation. Thanks
@captainmash-h8h
@captainmash-h8h 4 жыл бұрын
very clear and clean explanation, thanks!!!
@navjotmannan7303
@navjotmannan7303 5 жыл бұрын
Awesome explanation!!
@anim3197
@anim3197 3 жыл бұрын
Very well explained. Thank you!
@ryan-tabar
@ryan-tabar 2 жыл бұрын
# 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
@samwilliams4024
@samwilliams4024 5 жыл бұрын
Huge fan of your videos Corey! The functools.lru_cache decorator is also a great way to implement memoization on functions.
@jonathanwhite2715
@jonathanwhite2715 5 жыл бұрын
Thanks. Easy to understand
@charlesokoyoh
@charlesokoyoh 5 жыл бұрын
Thank you Corey
@smallblueflower
@smallblueflower 7 жыл бұрын
You're videos are great! Thank you!
@hustels
@hustels 8 жыл бұрын
Amazing tutorials.
@sairajdas6692
@sairajdas6692 6 жыл бұрын
Excellent video
@MaxS-v7x
@MaxS-v7x 7 жыл бұрын
Thank you for your work, perfectly explain!
@futurestar1000
@futurestar1000 8 жыл бұрын
such smooth explanation corey \/
@dipankararora2633
@dipankararora2633 5 жыл бұрын
your videos are too good.
@abuyusufansari6620
@abuyusufansari6620 7 жыл бұрын
Thank you for this nice explanation.
@hubertcombomarketing2693
@hubertcombomarketing2693 4 жыл бұрын
Good as always. Thanks.
@wartem
@wartem 2 жыл бұрын
This is brilliant
@luizfelipels7
@luizfelipels7 3 жыл бұрын
Such a fancy name for a simple idea.
@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.
@antoniosaqueton3293
@antoniosaqueton3293 4 жыл бұрын
Hope you can come up with tutorials on data structures or at the least, recursion. Please help a brother out!
@TheTruthFadeswithTime28
@TheTruthFadeswithTime28 6 жыл бұрын
Can you do a video on recursion ?
@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.
@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)?
@khireddinebelkhiri725
@khireddinebelkhiri725 5 жыл бұрын
thank you thank you thank you
@VictorSantos-yb8ir
@VictorSantos-yb8ir 3 жыл бұрын
Thanks!
@obed818
@obed818 2 жыл бұрын
Hello if you plan to use it i suggest you to check this video more up to date 👍 kzbin.info/www/bejne/ep-uqX58jadnhLM
@augiblutz2852
@augiblutz2852 2 жыл бұрын
well done
@jean-michelcid9594
@jean-michelcid9594 4 жыл бұрын
amazing!!!!
@maxim9280
@maxim9280 5 жыл бұрын
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 kzbin.info/www/bejne/ep-uqX58jadnhLM
@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.
@rohanpednekar8074
@rohanpednekar8074 4 жыл бұрын
Great !
@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?
@chengguanpropertysg9140
@chengguanpropertysg9140 4 жыл бұрын
The result is returned in the if block
@ashishkumarnath1259
@ashishkumarnath1259 4 жыл бұрын
You are god!!!!, thank you so much!
@snoopyjc
@snoopyjc 5 жыл бұрын
How are you using “print” without () ?
@yashrajvanshi17
@yashrajvanshi17 5 жыл бұрын
That program was written in Python 2.X version not in Python 3
@ziqb
@ziqb 4 жыл бұрын
All my life, I had been calling it caching ..
@poorna685
@poorna685 4 жыл бұрын
i thought he would explain about lru_cache
@stevendye249
@stevendye249 7 жыл бұрын
Why don't we need an else statement after the if statement in expensive_func?
@coreyms
@coreyms 7 жыл бұрын
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
@MrBrainOwl
@MrBrainOwl 7 жыл бұрын
Perfect!!!
@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.
@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.
@johnc7436
@johnc7436 4 жыл бұрын
Good
@abinash138
@abinash138 7 жыл бұрын
what is the use of sleep in this program
@coreyms
@coreyms 7 жыл бұрын
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: kzbin.info/www/bejne/h5yTq4iQjJKIla8 , 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 жыл бұрын
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?
Programming Terms: Combinations and Permutations
9:14
Corey Schafer
Рет қаралды 49 М.
JavaScript Memoization Made Simple!
11:22
The Code Creative
Рет қаралды 6 М.
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
Programming Terms: Closures - How to Use Them and Why They Are Useful
11:44
C++ Crash Course: Memoization
9:34
Nick
Рет қаралды 4,3 М.
Using caching and memoization to optimize Python performance
17:00
Sebastiaan Mathôt
Рет қаралды 8 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 579 М.
Programming Terms: First-Class Functions
15:28
Corey Schafer
Рет қаралды 288 М.
The Fastest Way to Loop in Python - An Unfortunate Truth
8:06
mCoding
Рет қаралды 1,4 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Algorithms: Memoization and Dynamic Programming
11:17
HackerRank
Рет қаралды 977 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 246 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 854 М.
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН