How can we multiply large integers quickly? (Karatsuba algorithm) - Inside code

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

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

  • @insidecode
    @insidecode  2 года назад +5

    Discover the new graph theory algorithms course: inscod.com/graphalgo
    🔴
    / \
    🔵-🔴
    | |
    🔴-🔵

  • @Paul-vg8vc
    @Paul-vg8vc Год назад +17

    I believe there's a typo at 6:01 - the fifth line should say "(a+b)(c+d)-ac-bd"

    • @crofux
      @crofux Месяц назад

      Thanks man

  • @markd2797
    @markd2797 3 года назад +24

    Jeez, you explain this very well. You don’t explain material in a generic way. Also, I love the animation.

  • @richardtobing5012
    @richardtobing5012 3 года назад +9

    this is a very well done video, the animation and the color palate are really smooth and the explanation is clear as day. Subscribed.

    • @insidecode
      @insidecode  3 года назад +2

      Thanks a lot for your comment!

  • @ryansamarakoon8268
    @ryansamarakoon8268 3 года назад +24

    This is amazing!! I learnt so much not just about the algorithm, but key concepts like merge sort, masters method and more. I'm waiting for the day you blow up 🔥 def sending this one to my friends

    • @insidecode
      @insidecode  3 года назад +3

      Amazing! Thanks for the comment and the support

  • @gimmametdeboys1505
    @gimmametdeboys1505 4 месяца назад +2

    Really liked the tree visualtion, made it so much easier to understand.

  • @yaswanthnani6563
    @yaswanthnani6563 11 месяцев назад +1

    this is a very well done video, the animation and the color palate are really smooth and the explanation is clear as day.

  • @saqlainsajid4067
    @saqlainsajid4067 2 года назад +1

    Some feedback about calculating the time complexity
    you say, the return statement has complexity O(n) but if you observe closely, the whole return statement is filled with O(1) operations,
    I think the function "ad_plus_bc" has complexity of T(n/2)+O(n), because it has a subtraction operation, subtracting/adding has complexity of O(n)
    The overall expression of complexity is correct.
    T(n) = 3T(n/2) + O(n) + O(1), where O(1) can be ignored in the presence of O(n)

  • @pirateboygaming2726
    @pirateboygaming2726 Год назад +2

    Best explanation of karatsuba algorithm.

  • @kshitijzutshi8278
    @kshitijzutshi8278 3 года назад +7

    Hi, PLEASE create more videos like this and Also add videos to playlist for easy lookup. Really appreciate it. Algo/problems related to Data science would be great as well.

    • @insidecode
      @insidecode  3 года назад +1

      Thanks for your suggestion!

  • @georgia6502
    @georgia6502 Месяц назад

    2 minutes in and i already have a much better understanding. absolute legend thank you!!

  • @samarthtandale9121
    @samarthtandale9121 Год назад +2

    Great explanation ! Underrated 100%

  • @gorantlakarthik2709
    @gorantlakarthik2709 3 года назад +3

    Apart from good explanation. The entire presentation is also so satisfying and I can see u put a lot of work behind it. Do more of them we will keep supporting you sir.

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

    This is some high quality material. Really appreciate it.

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

    I never knew that there is another algorithm to multiply. Thanks for increasing my knowledge 😍😍🥰🙏✌️

  • @sir_serhii
    @sir_serhii 2 года назад +3

    One minor thing that is missing here is how to Actually calculate big numbers that don't fit regular programming primitives as Int or Double

  • @richardpro8927
    @richardpro8927 Месяц назад

    We need more such videos
    Your channel is getting addictive ❤

  • @infwin5944
    @infwin5944 2 года назад +1

    Fantastic and easy to understand tutorial! Just want to point out that the last line of code might not work in the case of an odd number of digits, since you calculate half with n//2.

  • @harshmangalamverma
    @harshmangalamverma Год назад +1

    thanks for the video explaination.
    also, note that 1.58 is read as one point five eight, not one point fifty eight.

  • @modysy1660
    @modysy1660 3 года назад +3

    This tip seems very helpful. Thank you for sharing

  • @antoine2571
    @antoine2571 5 месяцев назад +1

    Exactly what I was looking for
    Thanks !

  • @polishane8837
    @polishane8837 5 месяцев назад

    Thank you so much, been looking for ways to make my multiplication more efficient

  • @BELLAOUAR_Mahmoud
    @BELLAOUAR_Mahmoud 3 года назад +2

    Ur explanation is very clear i hope to make more videos about unknown topics in computer science
    well done bro .

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

    Great platform and very helpful!! Keep Going! One of the rare channels which explain algorithm design in such depth...

  • @jeffbezos3942
    @jeffbezos3942 3 года назад +1

    This channel only need playlist clarification and it is perfect!

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

    Thank you for this video. Keep growing. It would be so great if in future you plan on making a course on data structures & algorithms- would probably be something to watch out for whenever computer geeks open youTube.

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

      Thanks for your suggestions

  • @lcarliner
    @lcarliner 3 года назад +2

    With quantum computer memories sometime in the future, if read only quantum memories could be invented, then huge indexed table could be used for instantaneous results. For single value function like trig functions, read only index tables would have advantage of single clock speed and absolute accuracy, as it is my understanding that different approximations have needed accuracy for only portions of the number space.

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

    amazing explanation,short and brief...made the concept easy for me. thanks 😍

  • @TheSacredSteve
    @TheSacredSteve 2 года назад +1

    Very well done video. I appreciate the care and quality.

  • @nihal-kabir
    @nihal-kabir Год назад

    teaching can't be better. thank you.

  • @AnuPAMAMUsiC
    @AnuPAMAMUsiC 8 месяцев назад

    this video saved my life! thanks

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

    I was wondering from some time ago if Toom-4 is equivalent with Karatsuba , from a complexity point of view, but that looks a bit impossible. Lately , I was able only to come with this. Considerring Toom-4 and also Toom-4 added those two terms multiplications (the ones from middle ), which are more like K-idea, only with two more multiplication comparing too Toom-4. (so we got 4+3 vs 4+5 complexity dilema). those 5 multiplications terms computed are all following some simple rule for product of 2 coetients and other 2, no matter which one of the 5 mult term we chose. So we might be able to reach to the conclusion that we can find the method Florin-4, Florin-8, etc, no so sure about its complexity thow so this may be just some joke offered by me to anyone wish to verify its complexity. Thank You, I like these style of videos on RUclips! ^_^
    P.S. digging this out i was needed to reformulate the K-idea , both with Toom one, by switching from geometric progressions to something more oriented on adds n diffs instead coetient products that looks the same to diffs that look the same. But this is a bit too complex to me, a bit hard to get the job done, need meds 2 times a day in any case, I mean only to be able to put these here, for example. Thank You! :-)

    • @mehdididit
      @mehdididit 2 года назад +1

      Mucho texto

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

      @@mehdididit I agree, I talk too much since I know myself >

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

      @@mehdididit Alrite, here some more nonsense, that might worth some translation 🙂
      consider ca in mod normal, logica de tip chat bot sau click programming / logic explorer, pentru utilizatori incepatori din gimnaziu/liceu ar cam trebui sa mearga binisor, ma gandesc ca macar atata pedagogie cibernetica ar cam trebui sa se gaseasca pe lume, spre exemplu la programarea in basic, sa ofere pe post de "mutare" din partea computerului, cateva optiuni pentru urmatoarea nstructiune de inserat , doar cu un click, in viitorul mic cod sursa al rutnei respective, provocarea fiind ca la per total, aplicatia gen logic explorer sa ma arate a ceva.
      Multumesc frumos!

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

    thank you!! best explanation of the concept imo

  • @jacktrainer4387
    @jacktrainer4387 3 года назад +1

    Fantastic as usual! May I ask what program you use to do your videos?

    • @insidecode
      @insidecode  3 года назад +2

      Thanks! I make the slides with PowerPoint

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

      Hahahahaha i was expecting some rare program, thats amazon amazon slides bro. Keep it simple

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

    Just wow! Thanks man... Keep up the good work!

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

    Brilliant explaination

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

    Never knew about this,might come in handy
    Thanks :)

  • @user-rf4vc7mt4d
    @user-rf4vc7mt4d Год назад

    Brilliant video. Thank you so much

  • @kishanmittal431
    @kishanmittal431 3 года назад +2

    It should be (a+b)(c+d) and you solved for that only but you have written (a+c)(b+d) at 6:10

    • @insidecode
      @insidecode  3 года назад +2

      Yup that's true thanks for mentioning it

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

    Amazingly clear

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

    Amazing explanation

  • @10_bhaveshbathija31
    @10_bhaveshbathija31 Год назад

    great explanation thanks alot for saving the day

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

    Great explanation, Thank you

  • @Ffatima79
    @Ffatima79 13 дней назад

    thank you this is so useful ,god bless you

  • @ardiris2715
    @ardiris2715 2 года назад +1

    This begs to be a homework problem in recursive LISP. Using binary numbers. LOL

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

    amazing explaination bro!

  • @donovanmurray7005
    @donovanmurray7005 8 месяцев назад

    Thank you this is so helpful :)

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

    Subscribed Sir,Amazing work

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

    His speech melody tells 'it's all very simple, seeee?' - My brain sounds drop to 40hz.

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

    hey amaizing video but i dont get it why in the time complexity calaculate the sum require o(n)
    it all sum why not o(1)?
    i mean at 8:20 at the below statement ?

  • @RUBAYATKHAN89
    @RUBAYATKHAN89 7 месяцев назад

    Did not understand why there's O(n) ? All the operations are O(1)

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

    An algo optimisation idea that can be inspired by the hardware predication techniques, applied to soft data numbers to be multiplied, arraies to be multiplied, others may too, I think that may give us something to think about. Never tested nor verified by me, sorry! :-)

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

    wow this helped so much thanks youuuu!!!!

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

    I can't understand why we store n // 2 in the variable half , I know it gives a wrong answer if we don't do that but why ?

    • @insidecode
      @insidecode  2 года назад +1

      Technically you don't need to do it, you can write n//2 everywhere but using a variable gives a more understandable code

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

    How does this work IN PRACTICE for standard 64 bit binary machines? Is there REALLY a savings? Or are much larger numbers (256 bit) needed for a practical improvement?
    Has this ever actually been implemented into processor microcode? If so, how did it work out?

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

      According to Wikipedia, at least 320-640 bits.

  • @arquier
    @arquier 3 года назад +1

    That algorithm is used to multiply big Matrix right?

    • @insidecode
      @insidecode  3 года назад +1

      just integers, maybe you're talking about Chain matrix multiplication?

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

      @@insidecode yes, looks like it can be applied on that case too

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

    Nice man 👍 keep up the good work

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

    Pardon me but i m still confused how does exactly it reduces the time complexity than the old way, i see a lot of arithmetic in this method too?

    • @KahHongTan
      @KahHongTan 2 года назад +1

      The trick is the part at 3:26. Divide and conquer works only if breaking a problem down and dealing with the sum of those smaller chunks is easier. It might not be, you might just end up with many small problems which added up is still the same problem. This is the case if you split two numbers you want to multiply, now you have twice the number of multiplications of integers half the original size. Split again, now 4 times the number of multiplications with integers of a quarter size. Same problem. But here, whenever you split two integers there's 3 new multiplications instead of 4. So you get to split the integers in half without doubling the multiplications needed.

  • @konstantinrebrov675
    @konstantinrebrov675 11 месяцев назад

    When I was in university I was assigned to implement this algorithm, and I struggled to understand it.

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

    Hi bro, that's realy high quality content
    I love ❤❤❤❤❤❤❤your accent daaam.
    Keep doing, Love from India🇮🇳🇮🇳.

  • @rehabemadel-dein6950
    @rehabemadel-dein6950 Год назад

    How to solve it using array by storing two numbers in 1D array with help of 2D array

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

    How do we do this if we have odd lengths of numbers?

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

    I have a fat expensive algorithm book in my hand that could not even explain how x became a*10^(n/2) + b. Yet it only took you 10 seconds to explain it...

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

    very great explanation!

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

    is there another way to get 3 multiplications?

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

    wow , its always worth watching

  • @gauravchaudhari618
    @gauravchaudhari618 3 года назад +1

    awesome man immediately subscribe to your channel

  • @ahadali3908
    @ahadali3908 5 месяцев назад

    PayPal link for paying back for this amazing explanation?

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

    This is helpful .. Thumbs up!

  • @ShashwatShourya-v4q
    @ShashwatShourya-v4q Год назад

    informative, thanks

  • @lukayt-content1613
    @lukayt-content1613 2 года назад

    Nice video but i don t understand why do we need this. Cant we just multiply the numbers? Initially i thought that the method will be for that numbers that when are multiplied are giving a very large number that doesn t fit into long long or double.

    • @insidecode
      @insidecode  2 года назад +1

      It's not about overflow because because we could use strings instead anyway, it's about the method we use to actually multiply the numbers. For small numbers we can use the brute force method we all know, but for big numbers, it's better to use the Karatsuba algorithm because it's faster

    • @Fred2-123
      @Fred2-123 Год назад

      It is for numbers that have hundreds of digits. Think about numbers like the number of nanoseconds since Jan 1, 1492. Or pi to the 100'th decimal place. On a 32 bit machine, what if you need to multiply two 14-digit numbers.

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

    Amazing Video!

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

    Thank you!!

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

    Great content. Thank you

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

    very helpful video, thanks heaps

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

    Really really useful

  • @sudalaitech4019
    @sudalaitech4019 8 месяцев назад

    Why calculating the result takes O(n)?

    • @sethdon1100
      @sethdon1100 6 месяцев назад

      Addition digit by digit is an O(n) for n digits

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

    سبحان الله والله عرفت accent تعك دزيرية 😂
    Anyways, thanks for the information it was really helpful, keep going 💜💜

  • @skay1012
    @skay1012 9 месяцев назад +1

    cool ♣

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

    thank u a lot bro .... best video ;)

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

    The best channel

  • @OKeefeist
    @OKeefeist 2 года назад +3

    If you talked a bit slower and clearer would be a 10/10

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

    Beautiful!

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

    I don't get it, why n is 2?

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

      Where did you see that n is 2?

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

    Aw this is amazing

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

    beautiful ty

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

    fascinating!

  • @rajarshimandal3235
    @rajarshimandal3235 2 года назад +1

    Thank u sir

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

    Need more such

    • @insidecode
      @insidecode  3 года назад +1

      The next videos will all be about CS algorithms!

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

    Thx a lot

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

    nice job

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

    thanks

  • @LeonidSaykin
    @LeonidSaykin 3 года назад +1

    that doesn't look quicker or simpler

    • @insidecode
      @insidecode  3 года назад +1

      It's quicker for large numbers, Karatsuba algorithm has an O(n^1.58) time complexity while the brute force method has an O(n²) complexity

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

    Amazing

  • @ShaneBassey
    @ShaneBassey 6 месяцев назад

    Calculator was made for the math💀💀

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

    nice man

  • @YoussefAhmed-is3gf
    @YoussefAhmed-is3gf 2 года назад

    you are super awesome

  • @yusufk5919
    @yusufk5919 11 месяцев назад

    goated video

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

    u da goat no bap

  • @Center.khawlaFaid
    @Center.khawlaFaid Год назад

    thanks a loot