Solving the Fibonacci Sequence with Matrix Exponentiation

  Рет қаралды 95,641

Gaurav Sen

Gaurav Sen

Күн бұрын

Пікірлер: 215
@killuazoldyck7705
@killuazoldyck7705 4 жыл бұрын
Its always that one Indian person that explains it better than your learning materials and the teacher combined
@alessandrocamillo4939
@alessandrocamillo4939 6 жыл бұрын
You’ve been the first and the best to clearly explain the math behind fast Fibonacci matrix computation .
@gkcs
@gkcs 6 жыл бұрын
Thanks!
@ITACHIUCHIHA-dr8sz
@ITACHIUCHIHA-dr8sz Жыл бұрын
6 years later, and still the best video explaining this on youtube!
@gkcs
@gkcs 3 ай бұрын
Thank you!
@shreyasahu481
@shreyasahu481 7 жыл бұрын
when the yellow tee turns blue magically! nice video though :)
@gkcs
@gkcs 7 жыл бұрын
Haha :-P Thanks Shreya!
@abhaypatil2000
@abhaypatil2000 5 жыл бұрын
also he wore spectacles
@shreyaghosh2956
@shreyaghosh2956 8 ай бұрын
Wow! Thank you for making it so simple to understand. This was the clearest explanation of matrix exponentiation.
@manishankar1593
@manishankar1593 6 жыл бұрын
I loved the Maths involved into this problem, fascinated!
@iprakhar22
@iprakhar22 7 жыл бұрын
Appreciate your work a lot, Man! Something I like about you is that you choose your words very carefully before speaking just so that every kind of audience can understand you.
@gkcs
@gkcs 7 жыл бұрын
Thanks Prakhar!
@vidhansharma1787
@vidhansharma1787 6 жыл бұрын
Thanks bhai.... People like you help guys ,those are not from good colleges in ind.. to improve their competitive programming skills......
@Speak4Yourself2
@Speak4Yourself2 5 жыл бұрын
Not even the best of colleges in India teach any Competitive Programming.
@Speak4Yourself2
@Speak4Yourself2 5 жыл бұрын
@ 'coDiNG cULtUre' starts from You. When you code, (and code well, with time and practice) your friends/juniors are inspired to follow in your footsteps. Over the years this inspiration spreads as a ripple effect batch after batch. Then the college calls itself as having good 'coDiNG cULtUre'.
@subhodip5293
@subhodip5293 5 жыл бұрын
Great Teaching. Your energy is very engaging to the viewer and your explanations are clear and intuitive.
@theIcemanYT
@theIcemanYT 5 жыл бұрын
the channel I should have found a year ago. Awesome explanation.
@gkcs
@gkcs 5 жыл бұрын
Thanks! 😁
@atulsaswat1153
@atulsaswat1153 4 жыл бұрын
At 17:45, when we do the final multiplication, we should consider f(1) = 1 and f(0) = 0 giving us f(14) = 377 & f(13) = 233. That doesn't defeat the purpose of the understanding though. Your explanations have a good buildup and that is probably why it's so appealing.
@rishavsaha5254
@rishavsaha5254 3 жыл бұрын
Yes, you are correct but in the beginning of this video, he assumed both f(1) and f(0) equal to 1.
@ashishchourasia2830
@ashishchourasia2830 Жыл бұрын
The best explanation for this on the internet
@andermerketegi1177
@andermerketegi1177 2 жыл бұрын
It really helped me understand how to apply Matrix Exponentiation for my particular problem. Great video, thanks!
@FeroChau
@FeroChau 6 жыл бұрын
This is amazing! It's so satisfying to watch this.
@tanishq2766
@tanishq2766 2 жыл бұрын
The way your eyes shined, when you said THE MATRIX ! NEO FOREVER
@akhilesh59
@akhilesh59 2 жыл бұрын
Best Explanation so far with reason behind each and every step! Loved it... Thank you Sir.. ♥
@saranshdabas4223
@saranshdabas4223 7 жыл бұрын
Learning a lot from your videos, they are unlike any other sources available for competitive programming...
@gkcs
@gkcs 7 жыл бұрын
Thanks Saransh!
@NiceBot724
@NiceBot724 6 жыл бұрын
This video needs a lot more likes than just hundreds
@gkcs
@gkcs 6 жыл бұрын
I agree 😉
@abhishekkarn8918
@abhishekkarn8918 7 жыл бұрын
I can add one thing here if anyone is stuck until what power do we have to calculate the powers: just do: 2^(floor(ln(n)) and you will get the required number. For n=13, you will get 2^3, which is 8. Hope it proved to be of some help. And Thanks a Lot Gaurav for such a brilliant video. You are literally one of the best. :)
@gkcs
@gkcs 7 жыл бұрын
Thanks Abhishek :-)
@adoq
@adoq 3 ай бұрын
i was just looking for a way to find fibonacci numbers quickly with pen and paper, i didnt get my answer but i got valuable dynamic programming knowledge lol. works either way
@gkcs
@gkcs 3 ай бұрын
Excellent!
@Rajat_maurya
@Rajat_maurya Жыл бұрын
6 years later also helping many of us
@viditmathur8437
@viditmathur8437 6 жыл бұрын
your explanations are awesome , I really like the mathematical explanations . This video really helped me understand the log(n) approach to find fibonacci sequence which i couldn't understand from texts :D.
@gkcs
@gkcs 6 жыл бұрын
Thanks Vidit!
@LuisaGrigorescu
@LuisaGrigorescu 4 жыл бұрын
Great explanation! You made math much easier to understand. All the explanations from the internet are to mathematical and imply having prior knowledge to all these terms and formulaes.
@dugong369
@dugong369 5 жыл бұрын
For those who aren't aware, storing the lower powers isn't needed (see wikipedia article on Exponentiation by Squaring for example). Following a sequence of squaring and multiplication determined by the binary bits of the exponent eliminates the need to store those intermediate results. It's probably better that you explained it the way you did though because that avoids a complication which isn't relevant to the main point, O(log n).
@Manojshankaraj
@Manojshankaraj 7 жыл бұрын
Great video Gaurav! Please keep posting such wonderful videos. Thanks a lot!
@udaysaiphanindra3138
@udaysaiphanindra3138 4 жыл бұрын
what an explanation sir, MIND BLOCK
@ZMacZ
@ZMacZ 2 жыл бұрын
Less coffee or more meditation, enhances calm during explanation.
@abhimanyubahree1455
@abhimanyubahree1455 5 жыл бұрын
Wow solid explaination!!! Very easy to understand
@securityintech
@securityintech 4 жыл бұрын
at 4:20 I don't understand why do we require f(n-1) in the matrix, if the conditions are satisfied, we got [1 1] and f(1) and f(0), both of them are 1x2 and 2x1 matrix, resulting will be 1x1.
@aayush_dutt
@aayush_dutt 6 жыл бұрын
Elegantly explained bro! Thanks a lot
@gkcs
@gkcs 6 жыл бұрын
Thanks!
@amoghdesai9138
@amoghdesai9138 5 жыл бұрын
Should have this channel earlier. Very concise and useful explanation :)
@sohanursohan2426
@sohanursohan2426 4 жыл бұрын
It's helpful.Good work brother. From Bangladesh ❤
@MegaAkash123456
@MegaAkash123456 7 жыл бұрын
Great tutorial! matrix exponentiation is very useful in solving such linear recurrences in dp problems.
@gkcs
@gkcs 7 жыл бұрын
Thanks Akash!
@themusicalmonk2732
@themusicalmonk2732 3 жыл бұрын
You are Simply Genius.. man..
@fenil861
@fenil861 2 жыл бұрын
Thanks for this video. It helped me in gaining good insights for the approach to this problem.
@khudkikhoz
@khudkikhoz 3 жыл бұрын
Exactly this depth all we need... tx brother
@parth7300
@parth7300 3 ай бұрын
Goat explanation 🐐🐐
@Chesstreamer
@Chesstreamer 5 жыл бұрын
Just scrolling through your videos and bazzinga, found this fibonacci video,i have once used the code without understanding it somewhere on codechef but now i have understand it thoroughly,very simple and lucid exlplanation of yours helped me a lot.can u do some more problems on dp like state reduction and those involving trees tha would be of great help
@beonthego8725
@beonthego8725 2 жыл бұрын
Bless you Gaurav. Thank you
@vijaypratap356
@vijaypratap356 4 жыл бұрын
bro i am frustated from data structure and algorithm but there is some which does not let it go.when i will see ur videos they encourages me to learn but i dont know what exactly to learn for understanding complex problems of ds and algo.how do you solve the problems in minutes thats really amazing.
@shaswatdas6553
@shaswatdas6553 4 жыл бұрын
17:45 "Both of them will be 1 and 1"
@uarangat
@uarangat 4 жыл бұрын
Wonderful teaching brother, keep it up. Helped a lot. Many thanks.
@xiquandong1183
@xiquandong1183 6 жыл бұрын
Very good explanation. Thanks !!
@gkcs
@gkcs 6 жыл бұрын
Thanks!
@purvampujari
@purvampujari 6 жыл бұрын
Thanks bro , helped me solve medium level ( broken clock ) problem of this feb18 long !
@gkcs
@gkcs 6 жыл бұрын
+Purvam Pujari Awesome!
@travelinGuitarist
@travelinGuitarist 6 жыл бұрын
lol
@jayshree9037
@jayshree9037 5 жыл бұрын
Any topic become interesting when it's you 😁 also those spects give me granny vibes😄🤫 Thanks😍
@gkcs
@gkcs 5 жыл бұрын
😂😉
@sivasainagireddi7956
@sivasainagireddi7956 2 жыл бұрын
such a great explination !!!! thanks broo
@siddhantsharma7107
@siddhantsharma7107 4 жыл бұрын
You've explained it wonderfully. Wow!
@sumit-kushwah
@sumit-kushwah 9 ай бұрын
Thank you Gaurav 💌
@beautifultime9031
@beautifultime9031 4 жыл бұрын
Very well explained. Thanks for sharing.
@Snehaa2296
@Snehaa2296 3 жыл бұрын
very cool intro GKCS!
@ManishKumar-kw7qe
@ManishKumar-kw7qe Ай бұрын
Great explanation
@kiransfitnesstips4095
@kiransfitnesstips4095 10 ай бұрын
Nice explanation bro...
@rethink20s
@rethink20s 5 жыл бұрын
Great teaching skill bro...
@RapartiChaitanya
@RapartiChaitanya 4 жыл бұрын
Loved this explanation!
@sunnysam69
@sunnysam69 6 жыл бұрын
Amazing bro. Very nicely explained. Have been struggling to calculate fibonacci term efficiently.
@gkcs
@gkcs 6 жыл бұрын
Glad it helped :-)
@nazrulhassan6310
@nazrulhassan6310 3 жыл бұрын
great explanation brother
@shaziasamreen8584
@shaziasamreen8584 4 жыл бұрын
Very good explanation
@BluEx22329
@BluEx22329 3 жыл бұрын
Sequences of threes? Wow that's the holy trinity. My mind is blown and im agnostic
@TravellerMann
@TravellerMann 6 жыл бұрын
Good efforts bro..keep it up
@gkcs
@gkcs 6 жыл бұрын
Thanks!
@AmanSharma-hi3fd
@AmanSharma-hi3fd 5 жыл бұрын
12:04 The Matrix XD , you are the chosen one.
@sarcaastech
@sarcaastech 4 жыл бұрын
Great video .. I saw some other video on the same topic but it was not engaging like this one ... ✌️🔥
@91vasanth
@91vasanth 4 жыл бұрын
Wonderful explanation Gaurav. That smile at 18:19 haha ! And I have one doubt from that point. How did you say that to raise to the power we just took log(n) time? and you also said something about the number of bits to represent that number. Could you please explain me this? I was so satisfied with the understanding until I arrived at this point ! :(
@gkcs
@gkcs 4 жыл бұрын
Hey Vasanth, thanks for the feedback 😁 This link will help explain the logn bits: qr.ae/TWyJOx
@ravirayal7590
@ravirayal7590 2 жыл бұрын
amazing and very informative video, thanks
@souryasaha4001
@souryasaha4001 7 жыл бұрын
Nice Explanation. Keep up the good work.
@gkcs
@gkcs 7 жыл бұрын
Thanks Sourya!
@angshumanbhowmik1020
@angshumanbhowmik1020 4 жыл бұрын
Amazing video sir👍
@srijanpaul
@srijanpaul 3 жыл бұрын
I remember this from the book SICP! It was an exercise in the first chapter iirc. I saw the solution on community scheme wiki and was very impressed by this way of thinking about the problem.
@omshree901
@omshree901 2 жыл бұрын
What is the full form of SICP?
@the_dark_kerm
@the_dark_kerm 2 жыл бұрын
Really great explanation
@gkcs
@gkcs 2 жыл бұрын
Thank you 😁
@prathameshautade2679
@prathameshautade2679 3 жыл бұрын
Amazing explanation dude:)
@tarunpatel8168
@tarunpatel8168 5 жыл бұрын
that an awesome explanation, thankyou for the video
@ronaldvonk
@ronaldvonk 5 жыл бұрын
Very nice explanation and nice correction :-). The only thing is: even though this way of calculation may seem efficient; the total sum wil rise exponential and will be difficult to hold in memory; even for low values of N!
@gkcs
@gkcs 5 жыл бұрын
Yes that's true, although most of the questions around this have us taking a remainder of the result. So ans % m turns out to be small enough to fit in memory :)
@ronaldvonk
@ronaldvonk 5 жыл бұрын
But you will store every 2^N th step of the Fibonacci sequence in memory, right Gaurav Sen? The 2^3=8th step is only [[34,21],[21,[13]] , but the 2^5=32th step is already [[3.524.578, 2.178.309],[2.178.309, 1.346.269]] and rising exponential; resulting is a lot of digits. Which step will you take the modulo m and with what purpose?
@ronaldvonk
@ronaldvonk 5 жыл бұрын
But you certainly gave me an idea for storing these exponential rising values as (mod 2^k) :-D. This may do the trick. Is that what you meant?
@gkcs
@gkcs 5 жыл бұрын
@@ronaldvonk yup 😁
@ronaldvonk
@ronaldvonk 5 жыл бұрын
Like: the actual stored values in the matrices too?
@9871aa
@9871aa 3 жыл бұрын
If you set F(0) = 0, like wikipedia says, you could have even a simpler algorithm: raise matrix to the n-th power and get the 1-st row, 1-st column element.
@gkcs
@gkcs 3 жыл бұрын
Good idea 👍
@rajatparab8116
@rajatparab8116 5 жыл бұрын
Awesome explanation Keep up this great work Thanks a lot broo👍
@manthankhorwal1477
@manthankhorwal1477 4 жыл бұрын
Why can't we use implementation of pow function to modify it to directly calculate for matrix same as we do it for a number ?
@arreankit
@arreankit 7 жыл бұрын
Thanks, Gaurav !! Nice Explanation.
@gkcs
@gkcs 7 жыл бұрын
Thanks Ankit!
@kautukraj
@kautukraj 4 жыл бұрын
Very helpful!
@joshua_dlima
@joshua_dlima Ай бұрын
Enjoyed it, thank you!
@gkcs
@gkcs Ай бұрын
Cheers!
@vanshgupta24
@vanshgupta24 Жыл бұрын
the curious thing about fibonacci is that every fibonacci is golden ratio times bigger than the previous fibonacci , like 8 and 5 are in the ratio of 1.6 or 8 is golden ratio times bigger than 5. early numbers dont show it but eventually the pairs starts to converge to golden ratio, so for any large n the fibonacci is phi raised to some expnonent of n (check yourself). so you can just return pow(phi,n)*base , base here is any suitable fibonacci number that has significantly converged, and n is new shifted target .
@gkcs
@gkcs Жыл бұрын
You won't get the exact number using this, but you will get an approximation.
@KaranDoshicool
@KaranDoshicool 4 жыл бұрын
very well explained
@wedonotgogymnow
@wedonotgogymnow 2 жыл бұрын
How to multiply those 2 matrices [1 1] x [f(n-1) f(n-2]?
@tanvirahmed-vu2xy
@tanvirahmed-vu2xy 4 жыл бұрын
In which order i will multiply the matrix?? If i take the reverse order is it correct??
@ankitmishra-dp9tx
@ankitmishra-dp9tx 4 жыл бұрын
Thanks alot for this video. Immensely helpful and love your passion while explaining the problem. Newly created fan :D
@zaid6527
@zaid6527 Жыл бұрын
thanks, very well explaned
@mansinawani8970
@mansinawani8970 5 жыл бұрын
Thanks for this amazing video...
@monideepde7413
@monideepde7413 7 жыл бұрын
Very nicely explained. Thank you
@gkcs
@gkcs 7 жыл бұрын
+Monideep De Thanks!
@rahulsaxena5015
@rahulsaxena5015 5 жыл бұрын
How do we find the matrix to be "exponentiated" in different questions?
@umangbehl8152
@umangbehl8152 2 жыл бұрын
good explanation
@Pro3512
@Pro3512 5 жыл бұрын
Why it is showing class not found exception when i ran the code in github in online IDE for JAVA ?
@gkcs
@gkcs 5 жыл бұрын
Lmgtfy.
@misudey3281
@misudey3281 7 жыл бұрын
Nice Video And good explanation :) liked it a lot :)
@gkcs
@gkcs 7 жыл бұрын
Thanks Misu :-)
@ktxh
@ktxh 4 жыл бұрын
hi, shouldn't matrix^0 be an identity matrix?
@khalilshaik6161
@khalilshaik6161 5 жыл бұрын
thanks dude!
@letsghoomo
@letsghoomo Жыл бұрын
good job Sir
@longvu2033
@longvu2033 4 жыл бұрын
very nice explanation =))
@neosapien247
@neosapien247 4 жыл бұрын
Damn, I wish I had teachers like this in college.
@sivanipentapati5538
@sivanipentapati5538 7 жыл бұрын
can u post the link of code??
@harshsrivastava5255
@harshsrivastava5255 6 жыл бұрын
FIBOSUM on spoj..
@amankumarkashyap400
@amankumarkashyap400 6 жыл бұрын
How can matrix multiplication be O(1) ?? let's assume that we are multiplying two n*n matrices ,than the time complexity will be O(n^3).
@gkcs
@gkcs 6 жыл бұрын
If the size is a constant, it can be assumed to be constant. N cube for 3 is a constant: 27 :)
@chalapathinagavarmabhupath8432
@chalapathinagavarmabhupath8432 4 жыл бұрын
Yeah thank you 😊😊.
@priyabratamallick7629
@priyabratamallick7629 6 жыл бұрын
Hey Gaurav , It is a wonderful explanation, but I found a small flaw in the explanation. i.e. f(14) is 377 not 610 and f(13) is 233 not 377. We are getting it wrongly beacuse you have considered f(0)=1 which is actually 0. Anyway thanks of your nice work dude.
@gkcs
@gkcs 6 жыл бұрын
Thanks Priyabrata!
@karthikrockrr
@karthikrockrr 2 жыл бұрын
Mind blown !
@mandavasairaghavendradines6582
@mandavasairaghavendradines6582 4 жыл бұрын
Hey, great explanation. Nowadays you are doing more of system design stuff. I think once a while you can also post more these kind of videos
@gkcs
@gkcs 4 жыл бұрын
More to come!
@mandavasairaghavendradines6582
@mandavasairaghavendradines6582 4 жыл бұрын
cool, keep going!!
@jayseagal3681
@jayseagal3681 3 жыл бұрын
Thank you so much bro
@subhajitdas2784
@subhajitdas2784 7 жыл бұрын
Man that was so good
@gkcs
@gkcs 7 жыл бұрын
+Subhajit Das Thanks!
Least Common Ancestor - Dynamic Programming on Graphs
13:10
Gaurav Sen
Рет қаралды 44 М.
The Fibonacci Matrix
13:38
Jared Bitz
Рет қаралды 2,6 М.
Одну кружечку 😂❤️
00:12
Денис Кукояка
Рет қаралды 2,1 МЛН
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 25 МЛН
4.3 Matrix Chain Multiplication - Dynamic Programming
23:00
Abdul Bari
Рет қаралды 1,7 МЛН
Fibonnaci O(LOGN) #INTERVIEWBIT most optimal matrix exponentiation
22:23
Code with Alisha
Рет қаралды 10 М.
One second to compute the largest Fibonacci number I can
25:55
Sheafification of G
Рет қаралды 406 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 98 МЛН
The magic of Fibonacci numbers | Arthur Benjamin | TED
6:25
Matrix Exponentiation + Fibonacci in log(N)
31:23
Errichto Algorithms
Рет қаралды 70 М.
The Egg Dropping Problem - Interview Question
17:25
Gaurav Sen
Рет қаралды 183 М.
Mathematics - Fibonacci Sequence and the Golden Ratio
24:54
The Organic Chemistry Tutor
Рет қаралды 1,1 МЛН
Одну кружечку 😂❤️
00:12
Денис Кукояка
Рет қаралды 2,1 МЛН