I missed putting a second argument (memo) at 6:16 when calling fib(). Sorry. Anyway, here’s an outline of this video: 0:00: Intro 0:38: What’s the Fibonacci sequence? 1:37: 3 steps for solving a problem with dynamic programming 2:21: Finding the n-th Fibonacci number with recursion 4:28: A memoized solution 6:37: A memoized solution - time complexity 9:24: A precursor to the bottom-up approach 10:45: A bottom-up approach 12:30: Demo with Python and Jupyter Notebook Sample code is available in Jupyter Notebook and plain Python at: www.csdojo.io/dpcode
@therohitsahani7 жыл бұрын
CS Dojo I am very interested in technology and related of it. And if in the future I want to get a job at #Google so what should I have learned before getting into the #Google
@nightlight31697 жыл бұрын
Is python automatic able to store that big of a int? Because I try to find very big number in the fib seq but nothing in Java can Gould something that long and big
@benjaminsteeth29667 жыл бұрын
You don't deserve Google. Google deserves you.
@Ahmad_hehe_17 жыл бұрын
YK i have a question please reply.I am taking your python lectures already should i take your dynamic language lectures?
@Rohitsingh24107 жыл бұрын
Hey YK .. i am a beginner with algorithms and data structures can you refer me some good video tutorials and books on data structures and algorithms. Thanks
@pguti7786 жыл бұрын
Thank you CS dojo !!! I've passed a job interview because of this!!! You're the best!!!
@stard17584 жыл бұрын
Are u serious?, can u explain to me what job exactly did u get and what they asked u exactly ? Thank u
@kossklepht38433 жыл бұрын
@@stard1758 Almost all the big companies are using dynamical programming problems during technical interviews.
@viziopuzi93393 жыл бұрын
@@rohitshekharsingh2579 right ! Kudos to being jerk of the year !
@ayushraj65253 жыл бұрын
@@rohitshekharsingh2579 Awww, Poor brain💩💩💩
@tongpoo89853 жыл бұрын
@@rohitshekharsingh2579 someone is bitter
@michaelw77693 жыл бұрын
Well explained! One suggestion for your bottom up approach is that you don't need to use an array with size n to hold all the numbers, you just need 2 variables to hold the previous two numbers, and keep updating them when iterating.
@igorthelight2 жыл бұрын
That's smart! ;-)
@charan_752 жыл бұрын
For anyone wondering how to do using two variables in bottom up approach. def fib(n): if n == 0 or n == 1: return n first = 1 second = 0 result = 0 for i in range(2,n+1): result = first+second second = first first = result return result
@codewithsheikh28052 жыл бұрын
If you just need result of nth Fibonacci but he is populating array.
@coffeedude Жыл бұрын
@@codewithsheikh2805he is just returning the final result, not the array
@Sant270 Жыл бұрын
using fib sequence to teach recursion and DP is a very bad idea
@TinOfBeans3217 жыл бұрын
You're great at explaining! I'm a final year comp sci student and have come across fib and dp countless times but this is the simplest and best example I've seen yet. Keep it up!
@CSDojo7 жыл бұрын
Thank you!
@RachitJain7 жыл бұрын
You should also checkout this video then goo.gl/StJCAq
@maxim92805 жыл бұрын
Well we had it in school. And I still don't consider myself good at programming
@HarshPatel-iy5qe5 жыл бұрын
Hey buddy from which university you're pursuing?
@raj_patel_435 жыл бұрын
@@RachitJain hey bro, i am your subscriber, your are legend
@raghavendra20963 жыл бұрын
I am following your data structures playlist and came across recursion where you mentioned dynamic programming and i came here. You are a great teacher with passion, that's what makes u separated from others. This is my opinion by seeing your videos. Sometimes some people teach some stuff which is also good but it might make you doubt yourself, here even though i have watched with just 50% focus (after a day long work) i could still understand. Thanks soo much for teaching us all for free, i feel grateful that we have internet and best teacher teaching it all for FREE!!!
@doumkatekz6 жыл бұрын
Thank you! I'm a developer without a CS degree. Never really needed it but I'm trying to level up my skills and seeking out the things I've missed. Been doing it most of my life and I'm probably twice your age, never mind ego and pride, I'll learn where the learning is. Excellent video and explained very clearly.
@CSDojo6 жыл бұрын
Thank you so much for saying that!
@TjMulyadi5 жыл бұрын
Ditto here , Bro. I'm aLmost 40 but age doesnt matter when it comes to Learning. Learn from younger ppL never bother me a bit... hey one day our young friend here might Learn something from someone even younger.
@jhguygih5 жыл бұрын
I have bacharel in System information which had very basic algorithms and now that Im 32 and studying those to improve my mind explodes in every video. Also he explains very well indeed.
@HanifCarroll4 жыл бұрын
Same! I'm a bit older than the fresh grads at 28, but I'm self-taught and have been programming for 3 years now. Within the last couple of months I decided to start learning more about data structures and algorithms, and boy, it's incredible what it's done for my problem solving abilities. I feel so much quicker and more confident now. And it actually uncovered an interest in numbers that I didn't know was there!
@onilbautista2 жыл бұрын
this is so nice! you go man!
@Lillshad-space2 жыл бұрын
Cs dojo am learning here in Kenya and I find how you teach, quite suites me well, keep it up helping others like me....
@kells9k2 жыл бұрын
that country and all the "people" there are disgusting
@brianmuhia29552 жыл бұрын
am also from kenya
@nemousama46376 жыл бұрын
Awesome video. I'm a professional software developer who has been programming for a decade, and I still found this video helpful to put a name to something I've been doing without thinking. Also, you have almost single-handedly erased my prejudice against KZbin videos as a medium for quickly conveying CS/programming concepts. You are concise, to the point, presentable, and easy to follow. You do not waffle or waste people's time with showboating. I will be recommending your channel from now on.
@thawsitt7 жыл бұрын
You only need 2 variables to store the last 2 fib values. The following code has O(N) time complexity O(1) space complexity. def nth_fib(n): a = 0 b = 1 for i in range(n - 1): temp = a + b a = b b = temp return b
@nekojackson9856 Жыл бұрын
The advantage of the video's style of memoization comes in when the same function is called multiple times. If the video's function has already calculated fib number N, and you now want to use it to compute fib M ≤ N, then the second function call just has to look up N in a pre-initialized array. That reduces computational complexity to O(1) for that second call
@Kokurorokuko2 жыл бұрын
The fact that the most efficient solution is so freaking simple is amazing.
@vidyaranyatj73066 жыл бұрын
Smart, Humble and Simple. You're the best my man.
@PrasannDeshpande4 жыл бұрын
This is the first time ever that I have gone out of my way to like a video. Had to open another chrome with a personal Google account(the school account won't let me log in), find the video again, and like it. Needless to say, the video is just excellent!
@domainxh6 жыл бұрын
I migrated from aerospace engineering background to cs roughly two years ago. I can code, but doesn't know much about cs fundamentals. I learned quite a bit watching your videos. Keep up the good work!
@nazli_muradova05 Жыл бұрын
I'm 9th grade student and i've started to learn python for 3 month, came across with using dp for solving eolymp tasks,this video helped me to understand the whole concept! Thank you!!!!!!!
@dhawalmajithia49594 жыл бұрын
I keep coming back here for a refresher every time I have an interview scheduled. Love this
@JoCS111522 жыл бұрын
For free... dude, u are goat. People these days dont know how much technology, with a good use and being aware of his cons, can help.
@vendels41546 жыл бұрын
I must say, this is a very nicely done video, the example problem is simple enough to grasp the concepts for DP beginners like me, but also complex enough to demonstrate the usefulness of it and also impact of the different complexities. I have always had a hard time understanding recursive solutions (my brain just tends to get overwhelmed from it), but after this I actually feel I have a better understanding. Thank you for making this!
@MASTERISHABH5 жыл бұрын
This is my solution for that question in Python which takes O(n) time with O(1) space. a, b = 0, 1 for _ in range(n): a, b = b, a + b return b PS: If you want to implement this in other languages, simply add a temp var when swapping a and b.
@comradepeter874 жыл бұрын
Well yeah that is the most common way of doing it. This example was really good in explaining dynamic programming because nobody is caught up in the solution, just the process.
@somerandomguy0003 жыл бұрын
For fib, dynamic programming is the way to solve the problem we introduced ourselves when we went from the classic procedural to the recursive solution. And then bottom-up is just going back to procedural but adding an extra linear space complexity
@jaylanlee9453 жыл бұрын
wasn't really the point of the video but since we're on it, you can also calculate the fibonacci number using the following formula: f(n) = (((1+sqrt(5))/2)^n - ((1-sqrt(5))/2)^n)/sqrt(5) this should have constant time complexity it's unreadable as fuck but whatever
@ranjim3 жыл бұрын
@@jaylanlee945 yeah its a math way around
@LaysarOwO2 жыл бұрын
you actually dont need a temp var: b += a a = b - a
@davidranney87235 жыл бұрын
This is an excellent explanation. You chose a problem which is just complex enough to illustrate the technique. You methodically go through the steps and explain each step completely. I wish more tutorials were like this one. Well done!
@lynnguyen86524 жыл бұрын
I've reviewed several DP resources, and none of them sit that well. Yours is the best and easiest to understand. I wish I started with your video. Would've saved so much time!
@minhthinhhuynhle91033 жыл бұрын
This is much better: kzbin.info/www/bejne/pXPXZmaPl7dsgc0
@anoops79746 жыл бұрын
i am a 3rd year computer science student , although i have already done with data structures and algorithms courses . i have never really felt understood . this video helped me so much , hope you will continue doing these to help students like me , i am definitely going to share your works on my class group . please never stop adding more videos , i am looking forward to all your upcoming videos . i love these so much , thanks a lot once again
@purejoymind170519 күн бұрын
Incredible video. I'm a developer with 2 YOE, and I've never felt confident in aademic algorithm much. Wayching this made me realize that many of the fancy names we use for some algorithms are just names, we use a lot of useful and correct techniques and methods without realizing we're using it.
@DadBodSwagGod5 жыл бұрын
I feel like an idiot. I never realized that Dynamic Programming wasn’t actually anything special. It’s just a few commonly used strategies for solving any given problem
@sabah83124 жыл бұрын
haha ... Same here
@nadiequintero99814 жыл бұрын
Well, you're not an idiot. You were just uninformed.
@ayemaeyalit33543 жыл бұрын
Is it just recursion or is it also something else?
@DadBodSwagGod3 жыл бұрын
@@ayemaeyalit3354 It's basically the idea of the algorithm changing priorities and not looping through stuff it knows won't give it a result, preferably in a way where it was designed to eliminate those possibilities in as few operations as possible. That, as opposed to the basic thing of just looping through everything. You've almost definitely done it without knowing the word for it if you've taken at least a few years of computer science classes
@MyFictionalChaos3 жыл бұрын
algorithms arent super advanced concepts. you have to remember the majority of computer science has existed in the past century
@keritans6 жыл бұрын
Took Algorithms and read books about this and didn't know exactly what it was. Watched this video and now I'm an expert! Love the detailed explanations!
@canastrao5 жыл бұрын
You know how to teach people. It is really helpful.
@alotlikees4 жыл бұрын
Your super power is turning abstract concepts into chunks that my brain can consume,.. programming alchemy. Gold!
@VideoNOLA5 жыл бұрын
Wonderful and helpful example! Of course, as a mathematician, my first instinct is to Google "explicit function for nth term of Fibonacci sequence", which yields either the Binet formula, or the more succinct alternative F(n)=⌊φ^n/√5 + 1/2⌋, where φ=(1+√5)/2 is the so-called golden ratio. Most recursive functions can indeed be rendered explicitly, though it's not always obvious or easy how to accomplish this.
@sakshijuyal98775 жыл бұрын
The way he has explained is simply amazing....
@ricardoorellana11686 жыл бұрын
In the recursive calls of fib, you forgot to add the memo list, it should be: *result = fib(n-1, memo) + fib(n-2, memo)* Great video and explanation!
@wangsherpa28014 жыл бұрын
You are bit a confused friend. Watch the video again there're two functions one takes one argument and another one takes two.
@nitinat35903 жыл бұрын
@@wangsherpa2801 In the memoized solution when the recursive call is being made memo needs to be passed
@Vens83 жыл бұрын
That was just a pseudocode so it wasn't necessary. He did that during the demo of the actual code.
@di3g044 жыл бұрын
Man, the best explanation in KZbin, I've been trying to better understand a topic for about an hour.
@kirtipurohit12374 жыл бұрын
hey! I'm a first year student and I love programming alot. These topics aren't taught to us in college yet but my love for programming and computer science brings me here . Please make more videos with new concepts and tips for students who have just started programming !!! Thank you!
@akankshasingh30756 жыл бұрын
This is the best explanation of DP on KZbin. Have exam in 2 days and this really helped me in understanding basics. Thanks for this. Keep making more such videos.
@abraiyan79843 жыл бұрын
This is mind-blowing! Thanks, Dojo.
@thenotebubble6 жыл бұрын
This is by far the clearest explanation of dynamic programming I've seen! It's a topic I keep having to relearn every now and then but I think I finally truly understand it now.
@mrhyperboss42047 жыл бұрын
Really amazing I saw your channel when it was 10k now 137k with in a year congrats
@arnabdas29677 жыл бұрын
Me too
@1ycx6 жыл бұрын
Now 700k
@geekyprogrammer48316 жыл бұрын
now 800k :O
@klarnorbert5 жыл бұрын
879k :D
@ahfadm43115 жыл бұрын
923k :O
@hyrummoses18513 жыл бұрын
I'm a sophomore in CS and was struggling to understand dynamic programming and how it differed from regular recursion. After watching this video it makes perfect sense and I can now implement it in my future programs. Thank you so much!
@cwagnello6 жыл бұрын
At about the 6:30 mark when talking about memoization the array never gets the values of fib(1) or fib(2). The way the code is set up it falls through and then returns fib(1) and fib(2) at the check for n == 1 or n == 2. The comparison at the end is a nice touch to teach about a potential drawback of a recursive solution.
@amith89rm4 ай бұрын
My Bachelors would have been a lot more awesome if I had a teacher like this guy!! Great explanation. So glad I found this channel!!
@pweddy15 жыл бұрын
This just reinforced my feeling on recursion! When efficiency or memory usage is important, find a different solution! The bottom up approach was what I got out of analysis of algorithms 25 years ago! But people today don't seem to be taught that today?
@momonga.5 жыл бұрын
Idk I just had my algorithm design final today and we had two DP problems that totally destroyed me 😭
@KalimbaRlz3 жыл бұрын
the best explanation of dynamic programming I've ever seen
@pranavmishra93665 жыл бұрын
lots of love from India brother, you are awesome in explaining things in detail. god, bless you.
@kitgary3 жыл бұрын
I have failed for many programming interviews as I don't know how to solve DP problems. This video is really life saving!!! Thank you so much!
@roots67707 жыл бұрын
After that make 10-12 videos giving more examples of it. That would be awesome 😃✌
@savithak.65164 жыл бұрын
Can you please cover the pattrens discussed in this course www.educative.io/courses/grokking-dynamic-programming-patterns-for-coding-interviews?affiliate_id=5457430901161984
@ankitadey90407 ай бұрын
I was so confused reading the university notes on DP. But now after this video, it all makes so much more sense. I've learned a few algorithms using DP but it's mostly because I understood the logic somehow, but as for DP, I didn't try to understand that particular concept much. Now I feel more confident about it. Thanks a lot!
@AkshayNehe_invincible5 жыл бұрын
Great explanations! Thanks for these awesome videos. Similar to the call stack overflow issue with the recursive solution, I was thinking about the extra memory utilization by the bottom-up approach. The presented solution uses about O(n) memory but in each iteration we only need to access 2 elements from the array so we can even implement this using constant space by storing only previous two values instead of all values from the start. So savings on both space and time 🙂
@praveenchouhan63884 жыл бұрын
the best explanation i have seen on DP till now which covers all aspects of DP - naive, memoized and bottomup, excellent work!!!!!!!!!!!!!!thanks
@EDemircivi5 жыл бұрын
amazing explanation, thanks :) keep up the good work man!
@mereel774 жыл бұрын
Struggling to understand DP...this was a fresh perspective, really helped, thanks. The call-out to skip recursion and just fill in the table left to right is a game changer.
@dipikamandal53347 жыл бұрын
It's so simple. Thanks 😊 Please make more videos on dynamic programming.
@jithinp82346 жыл бұрын
😓😓😓simple....
@hind22022 жыл бұрын
Thank you. I really couldn't understand the difference between the 3 approaches from textbooks until watching your video.
@danielchang24876 жыл бұрын
Can anyone explain why 2n+1 for time complexity in 8:19 ? Let's say we run fib(3,memo), then there would be 3 times the function getting called ( fib(3), fib(2), fib(1) ), NOT 2n+1 = 7 ....
@danielchang24876 жыл бұрын
@Chris Blackwell still don't get it... :( can you give an example? is number of operations for fib(3,memo) = 2n+1 ?
@joshking95376 жыл бұрын
@@danielchang2487 Did you find out?
@danielchang24876 жыл бұрын
@@joshking9537 not yet..
@metalore6 жыл бұрын
I noticed that too. I think it should be 2(n-2)+1 for n>1. The n-2 is because the first 2 indexes don't call the recursion.
@arjun11946 жыл бұрын
@@danielchang2487 imgur.com/a/7x0yQiw
@BlaqueT9 ай бұрын
This was a great quick intro to dynamic programming! I feel like I'm prepped with enough basic understanding/questions to go into my upcoming lecture with curiosity instead of fear :) thank you!
@jaspersasa68686 жыл бұрын
THANK YOU SO MUCH : well explained
@nadamson142 жыл бұрын
This is THE best DP video on KZbin! The example you use is very simple but you really helped me understand what this approach is all about
@shourya4367 жыл бұрын
Sir,please take a question from codechef long challenges that are hard and based on dynamic programming,graphs,segment tree and more and please explain us that solutions...it would be very kind of you if you could help😃
@simplifiedsolutions22977 жыл бұрын
yes sir plz help
@derpina6157 жыл бұрын
Yes agreed. Please pickup a harder example. Make this a series!
@backslash88745 жыл бұрын
Yup that would be great...
@VivekSharma-nj3xd5 жыл бұрын
Yes!! Please do sir
@AnandPandeyHere4 жыл бұрын
I post solutions of famous coding interview problems with proper explanation and codewalk. If anyone's interested can have a look at the videos. It will be really helpful for those preparing for placements.
@ForgetNetThrottling7 ай бұрын
I have a masters in computer science, and this is the first time I've seen this concept explained this well. Had you been my prof way back, I'd definitely have gotten better funding in grad school!
@rahulr67234 жыл бұрын
in the third last line, while calling "fib(n-1) and fib(n-2)", we would have to pass memo right. meaning "fib(n-1, memo) + fib(n-2, memo)" I think this code will show errror.
@ivandrofly3 жыл бұрын
Yup
@osacognitive30203 жыл бұрын
Actually, wouldn't it need to be a global variable? Passing in memo wouldn't help us "remember" the result, would it?
@osacognitive30203 жыл бұрын
Never mind, just realized it depends on whether we are passing by value or passing by reference.
@rahulr67233 жыл бұрын
@@osacognitive3020 Once you declare a data structure globally you dont need to pass that every time. Here it will show error because the fib function takes 2 arguments but in the last 3rd line only one argument is passed.
@user-ww1wh3wz5d4 жыл бұрын
dude you are a legend. helped me so much with my dp project. so much more helpful than my prof
@roshanmahtir9406 жыл бұрын
0:40 Fibonacci sequence starts with 0, 1 by the way.
@xCwieCHRISx5 жыл бұрын
learned it the same way. F(n) = F(n-1) + F(n-2) and F(0)=F(1)=1 defined for natural numbers including 0 to be mathematical correct ^^
@krupt59954 жыл бұрын
Fibonacci is a sequence as its name defines so, thus that it is a function with a domain of the Natural Number's set, which means that what you are saying is true but in sequences, 0 is not usually used to avoid complexity. That's why often mathematicians use these elements S1, S2, S3...Sn.
@beltusnkwawir29084 жыл бұрын
I have always believed simplicity is fundamental basis for explaining and understanding any complex concepts. You just proved that here. Thanks @CS Dojo explicit and easy to follow video
@blackraven60493 жыл бұрын
Can all DP algorithms be implemented with a bottom, up approach?
@brieananichole5 жыл бұрын
You are my hero, the difference between the recursive approach vs the bottom up approach is incredible. Thanks for making these ideas so easy to understand!
@amishashukla19445 жыл бұрын
Amazing video.....I love your videos. They are really helpful 😇.....Keep going, more power to you🎉✨💪🔥
@SuineXYT4 жыл бұрын
Thank you very much for your video. It was clearly explained, and much easier to understand than my college textbook. It took you 5 minutes to help me understand what I couldn't in a few hours of reading. Thanks!
@sergey1985 жыл бұрын
You don't even need an array in your "bottom up solution"
@YassineAbdulRahman5 жыл бұрын
can you calculate it on the fly without array?
@sergey1985 жыл бұрын
@@YassineAbdulRahman of course, you only need two variables storing two previous values.
@chiragasourabh60445 жыл бұрын
Yeah exactly .. instead of filling up an array with n number of items u can use two variables storing previous two states and on every iteration update them . As temp = v1 , v1=v2 ,v2+=temp
@MrNettoon5 жыл бұрын
@@chiragasourabh6044 That's exactly what i thought but its O(n) is bigger
@mohammedfaour41365 жыл бұрын
if an if-statement is before the for loop stating the if bottom_up[n] exists then i can cut the time because i can return the value instanty without entering the loop , this is useful if i have more than one call for the function, most useful in competitive programming
@ethansodaro39453 жыл бұрын
oh man...You literally nailed all that stuff in a few! A bigggggg time appreciation from me.
@MegaMazenko7 жыл бұрын
Your code for the memoization solution is incorrect. You have result = fib(n-1) + fib(n-2), where you should have result = fib(n-1, memo) + fib(n-2, memo)
@rohanshah74467 жыл бұрын
Mazen Abusharkh isn't it simply better to declare memo as global and never pass it...?
@MegaMazenko7 жыл бұрын
Rohan Shah, at 6:55 YK has else: result = fib(n-1) + fib(n-2) where his function is defined as def fib(n, memo): And yes, it is better to declare it globally and never have to pass it as a function arg
@varesz93117 жыл бұрын
Mazen Abusharkh checked the comments only to see if anyone else recognized it :D
@kenhaley47 жыл бұрын
The actual code at 12:37 is correct. Also, passing the array as an argument is no big deal if it's passed by reference. Some people argue against the use of globals wherever possible.
@namlehai27377 жыл бұрын
Not making everything global is a good habit. But in this case its ok
@devenderbhatt4215 жыл бұрын
By seeing ur video and ur explaination ,it obvious that you have a deep knowledge of dp.
@shugabaabrahamwuta18334 жыл бұрын
When you called fib(n-1), did you leave out the second argument memo on purpose?
@sr_snehil4 жыл бұрын
That was not the original code... check the original code in the description. There, he made two different functions fib() and memo()
@MaXxamillion004 жыл бұрын
Really impressed with the video. I liked the way you presented code that you had already written, line by line, while explaining the code. It was really clear and not overwhelming. Thank you for making this!
@lesterdale72765 жыл бұрын
YK I love your channel, however I am always disappointed when everyone uses Fibonacci as an demonstration of dynamic programming. Could you please offer a different application of this programming technique
@plouf19695 жыл бұрын
I agree - there are a couple of examples that are not that complicated, but have real applications, and show the challenges met when doing dynamic programming.
@JCho-pi5jz3 жыл бұрын
I rarely give compliments bc I always have something that bothers me about the video (i don't compliment tech videos) but WOW!!!! you're exceptional. your videos are AMAZING!!!! I have a physics degree went into DS/ML like most of us do and now I'm switching to CS. Your videos are so clear cut your speech is impeccable, perfect pace, sound and visual, and a nice flow. I can tell you did multiple takes or practice (if not that's REALLY impressive). combined with all you have a great knowledge base and present it *flawlessly*. Most of my interviews were things you covered and your videos are also the right amount of time. It's short enough to maintain interest and long enough to give you thoroughly. It's kind of a shame that people will only really tune in during interviews or when they are learning CS/DS. You structured it well with depth and breadth. You go into a great overview and then have videos that go into more specific which is WAY better than having one long video. I wish I saw these videos before just doing a bunch of leetcode problems. It's a great clean organized way of explaining the tools. I didn't know how many leetcode problems were enough but this is great! I used your info so much on interviews. It's so memorable and keeps my attention (I have ADHD so I'm really picky with videos). I'll definitely share your channel with people interviewing or anyone new to coding. If you decide to leave KZbin please keep these videos up. Also, you don't have that annoying "Aren't you amazed how smart I am?" arrogant vibe. You have a very humble, enthusiastic energy. Okay, this comment is way too long it's kind of creepy, but I'm a girl so how dangerous can I be? I just really wanted to let you know your videos are powerful and I really appreciate the time you take to edit them, it makes watching/learning so much easier. I know it's a lot of effort and it might not be obvious to people watching bc we're so focused on learning but I thought you should know it sets you apart.
@lokeshsivakumar39275 жыл бұрын
Help! as I am getting: Traceback (most recent call last): File "/Users/lokesh/Downloads/fibonacci.py", line 28, in fib_2(n,memo) File "/Users/lokesh/Downloads/fibonacci.py", line 15, in fib_2 if memo[n] is not None: IndexError: list index out of range
@aashishmehtoliya58005 жыл бұрын
just do n-1 in memo[n] in place of n , because array starts with index 0 and memo[n] covers 0 to n-1.
@yanistancheva30764 жыл бұрын
2 hour lecture explained in 14 minutes, thank you
@NikhilSinghNeil5 жыл бұрын
didn't understand the part starting from 7:43 when the explanation for the second 'if' starts, explainig why it is n times
@muhammadrahmatullahrahman15345 жыл бұрын
it is n times because we don't need to call a recursion anymore since we already have the result of fib(n) inside the memo, that's why after the else block we do the operation to input result into memo
@navjeetkaur57424 жыл бұрын
U r the best teacher tough topics become easier when YK teaches. Thank u so much. God bless u.
@umangchaudhary187 жыл бұрын
Make videos for more complex programming questions (generally asked in interviews and technical online tests) which can be done by dynamic programming.
@RahulGodse5 жыл бұрын
I learn things faster by watching rather than reading and you are simple awesome.
@echtcipher66825 жыл бұрын
What is bottom up approach in programming?
@b_1729-j8j6 жыл бұрын
Earlier I thought DP is very hard concept,but after watching this video,I got interest in DP,thanks CSDojo
@asdf-od5nm7 жыл бұрын
Make some programming video on your pc
@umeshkadam1133 жыл бұрын
The video is great. You explained the concept very quickly that what exactly it means in a simple language without wasting time on other things.
@nickharalampopoulos5 жыл бұрын
Great explanation! Thanks. One error though. fib(3) = 2 because Fibonacci series starts with 0, 1 not 1,1. So it is 0, 1, 1, 2, 3, 5, 8 etc. One of the many sources www.mathsisfun.com/numbers/fibonacci-sequence.html
@RaineWilder3 жыл бұрын
In the bottom up approach you can get the Space complexity down to only O(3) as you don't need to store the whole array, just the last 2 values calculated, and only where n>=3, when n
@jjfrancay45447 жыл бұрын
Hey YK! What is the best book/textbook to learn programing and basic CS?
@aizazchaudary7 жыл бұрын
JJfrancay there's plenty of books you can find on Amazon but I highly recommend something like Codeacademy. Very good resource for basic cs.
@gildardorosas85877 жыл бұрын
CS is all about algorithms. The bible in CS is: Introduction to Algorithms www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844. Disclaimer this book is hard.
@sodium24965 жыл бұрын
Hi, Great video. For bottom-up solution your space complexity is O(n) since you create an n-array. You don't need to store all the values. You just need n-1 and n-2, you could store them in 3 item array and update the values with each iteration. So time-complexity would be O(n) and space complexity would be O(1) Here's the code; public double fib(int n) { if (n
@salman-farooq-sh5 жыл бұрын
aaaaah! "computation"! not competition! had me confused there
@Shingorani4 жыл бұрын
Excellent explanation. This is the best channel I've found for preparing for coding interviews!
@somerandomguy0003 жыл бұрын
Minor: Actually fibo starts with 0 and 1. Not with two 1s
@William_Clinton_Muguai3 жыл бұрын
It starts with: 0, 1, 1,...etc
@user-jk2po3cz7d3 жыл бұрын
@@William_Clinton_Muguai Well zero is optional. It adds nothing to the sequence.
@stanmann5712 жыл бұрын
The naive fib starts zero,one. The fib method can be used with any 2 seeds with interesting and amusing results
@luckydice55203 жыл бұрын
Took me a while to fully grasp the entire video but regardless I got it all now. Use this as a friendly reminder that smartness is not what matters but what does is the decisions you make to keep trying because you will get it done.
@stc28285 жыл бұрын
14:07, the largest number I ever seen
@zihanqiao28502 жыл бұрын
Clear explanation with an easy example. I really love the coding part and show the time difference!
@matthewsmit59306 жыл бұрын
GIVE ME YOUR PINGUIN
@taylormcneil22855 жыл бұрын
This video was super helpful! The first time I saw dp, it was explained in a very complex way. This is so simple!
@JoelRevzen12 жыл бұрын
I'm having a hard time trying to learn this topic via an internet course, your tutorial clarifies this important issue , thanks alot
@janeikeliu3 жыл бұрын
Thank you for this! This was very easy to understand and I caught that error at 6:16. Keep up the great work!
@janvikalra_9 ай бұрын
fabulous video - thank you! loved the jupyter notebook example at the end that proves the value of the bottoms up approach
@peterjuma3772 жыл бұрын
Thank you my friend! you are a good teacher. it was very difficult to me but through this tutorial i get a concept very easy.
@lye1_16 жыл бұрын
So much clearer than our professor!
@RumeshEranga5 жыл бұрын
Wish your channel was available when I did my undergrads. Great stuff.