Fast Multiplication: From Grade-School Multiplication To Karatsuba's Algorithm

Sdílet
Vložit
  • čas přidán 6. 03. 2019
  • Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe.com/pricing
    📹 Intuitive Video Explanations
    🏃 Run Code As You Learn
    💾 Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Question: Can we multiply 2 numbers using less than n^2 atomic multiplications? Yes, we can.
    Update: There is O(n*log(n)) integer multiplication now: hal.archives-ouvertes.fr/hal-...
    Karatsuba Multiplication On Wikipedia: en.wikipedia.org/wiki/Karatsu...
    You don't need this for the interview.
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech
  • Věda a technologie

Komentáře • 164

  • @BackToBackSWE
    @BackToBackSWE  Před 5 lety +17

    Table of Contents:
    The Problem Introduction 0:00 - 0:42
    Analyzing Grade School Multiplication 0:42 - 2:09
    How Do We Think About Doing Better? 2:09 - 3:06
    Ok...Can We Do Better? 3:06 - 3:30
    Let's Try A Divide & Conquer Approach 3:30 - 4:22
    Redefining x & y In Terms of Our Segments 4:22 - 6:11
    Multiplying The New Definitions Together 6:11 - 6:53
    We Now Have An Equation For The Decomposition 6:53 - 8:14
    Raw Divide & Conquer Approach: Exact Additions 8:14 - ...
    Establishing The Worst Length From Multiplications 8:44 - 9:24
    Handling The 2 Multiplications On The Edge 11:15 - 13:47
    End of "Raw Divide & Conquer Approach: Exact Additions" 13:47
    Raw Divide & Conquer Approach: Recurrence 13:47 - 16:43
    Raw Divide & Conquer Approach: Solving The Recurrence 16:43 - 21:50
    Raw Divide & Conquer Approach: Summing The Work 21:50 - 23:37
    A Breakthrough: Karatsuba's Insight & Analyzing Additions 23:37 - 27:18
    Karatsuba's Algorithm: Recurrence 27:18 - 28:14
    Karatsuba's Algorithm: Solving The Recurrence 28:14 - 30:28
    Karatsuba's Algorithm: Summing The Work 30:28 - 31:17
    How Did Karatsuba's Do? 31:17 - 32:48
    Wrap Up 32:48 - 33:50
    Mistakes:
    31:20 -> O(n ^ lg(3) ) is the asymptotic bound on the additions. Karatsuba's does not do this exact amount of additions in the worst case since constants were dropped. If you look at the equation on the board, it can be further simplified to see that there will be constants in front of the atomic multiplication symbol.
    Update -> There is O(n*log(n)) integer multiplication now: hal.archives-ouvertes.fr/hal-02070778/document
    Karatsuba multiplication is not the fastest method for multiplication. Wikipedia: "The Toom-Cook algorithm is a faster generalization of Karatsuba's method, and the Schönhage-Strassen algorithm is even faster, for sufficiently large n."

  • @hanat18
    @hanat18 Před 3 lety +14

    my heart jumped when I heard him speak Amharic lol but loved the content. glad to have come across this channel, a new fan!

  • @sleepingsounds2222
    @sleepingsounds2222 Před 2 lety +3

    Wow Ethiopiawi neh ende ...
    Keep it up bro you are incredible

  • @abelkidanemariam6485
    @abelkidanemariam6485 Před 4 lety +68

    when he speaks amharic i started searching for another opened chrome tab

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +2

      hahahahaha what

    • @abelkidanemariam6485
      @abelkidanemariam6485 Před 4 lety +3

      ​@@BackToBackSWE great video !!

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      @@abelkidanemariam6485 lol, what does it mean

    • @milindyadav7703
      @milindyadav7703 Před 4 lety +1

      @@BackToBackSWE it means he thought the video is in another language and he started looking for another one...which...he had already searched for but was in another chrome tab

    • @bonbonpony
      @bonbonpony Před 3 lety +4

      Yeah, not the brightest way to start a video, unless you want 90% of people clicking the close button before even having the chance to get the joke :q

  • @yoyokojo651
    @yoyokojo651 Před 3 lety

    Thank you! I could not bear whatch my profs dull video-lectures on this topic anymore, im happy i found someone enthusiastically explaining this by examples!

  • @achyuthvishwamithra
    @achyuthvishwamithra Před 4 lety +6

    Thank you for this video, this greatly helped me in understanding Karatsubi algorithm which is used in my course for polynomial multiplication. Superb content!

  • @OmarAhmed-zg2fw
    @OmarAhmed-zg2fw Před 5 lety +11

    Wow, I feel miserable. That was my algorithms year project, 4 years ago and i totally forgot it and forgot its logic along with those Latin letters and yet I'm here stumbled upon this video while i'm preparing for my interview at Amazon.
    Love your work and the effort.
    Keep it up dude.

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      thanks, yw

    • @yadneshkhode3091
      @yadneshkhode3091 Před 4 lety

      how to get interview at these companies?? no one is ready to give referral and they dont even look at resume if i send them one

  • @tonyz2203
    @tonyz2203 Před 4 lety +2

    I had struggles with the medium level questions but after watching your videos, they don't seem confused anymore. I am going to purchase the one year subscription of you website.

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      Nice, well we have a lot to go. We are working every day to achieve our mission of giving people exceptional interview outcomes.

  • @alessiodenny6123
    @alessiodenny6123 Před 4 lety +1

    excellent !! thanks . You are a great teacher. Could not understand this topic in school after 3 hours of lectures, and I understood it in 5 minutes after watching your video.

  • @roberthoffmann930
    @roberthoffmann930 Před 3 lety +2

    Thank you so much! Really rescued me and i like your positive vibe!

  • @vyomchandragallani3645
    @vyomchandragallani3645 Před 4 lety +1

    Very nice explanation , very nice work , and when I see detailed description of the video and in comment ,really hard working man !! Keep it up ! And thank you very much for this kind of explanation 🙌🙌🙌

  • @ericwilson8665
    @ericwilson8665 Před 2 lety

    Thank you so much. I wish my professor had watched this before attempting to teach it. Just brilliant.

  • @geraldcerna516
    @geraldcerna516 Před 3 lety +3

    When the video started I was like, "OK, it's time to open the subtitles." LOL. But as always, great video and a very articulate explanation. Thanks!

  • @clee6030
    @clee6030 Před 4 lety +8

    Hey! I really appreciate your work and you've been helping me a lot throughout my studies!!! Can you please make more posts on Greedy?

  • @juliancabezaspena3508
    @juliancabezaspena3508 Před 3 lety +2

    I am having this in my algorithm class, this really helped me!!!

  • @raghavendrakaushik4871
    @raghavendrakaushik4871 Před 3 lety +3

    Great explanation,
    cleared many of the queries!
    thanks a lot

  • @saurabhmahra4084
    @saurabhmahra4084 Před 3 lety +2

    CS guys are just mathematicians wearing ninja masks.
    You're awesome man, great video. Honestly, I had never seen such detailed complexity analysis for Karatsuba's Algorithm, and believe me it is important. I have seen CP problems based on the application.

  • @ariellelucca7755
    @ariellelucca7755 Před 4 lety +4

    For my master's I'm doing a research on applying KOM algorithm on hardware. It is a very interesting topic for it applies on my research subject. So I just want to tell you that, even though for most people this may not be important, for certain people it will be a treasure. So, thank you!

  • @stephyjacob1256
    @stephyjacob1256 Před 5 lety +5

    Hey bro, I am continuously following your channel .. It will be helpful if you make more video on Graph based problem-- Find the number of islands, Snake and Ladder Problem,Minimum Cost Path with Left, Right, Bottom and Up moves allowed, etc ...

  • @siddhantsharma4011
    @siddhantsharma4011 Před 7 měsíci

    Best explanation of Karatsuba algorithm. Thank you very much.😊

  • @clarice4072
    @clarice4072 Před 4 lety +2

    You are amazing man. Thank you so much for this

  • @shafanm
    @shafanm Před 3 lety

    Hi thank you for creating this channel really valuable material. I have a general question, am not familiar with any of the content of the channel but I am eager to learn and understand it. I am not sure what playlist to watch first and advanced my way up. It seems that it is important to build my base knowledge and to that I can't jump from one video to another but need to do it in a specific order so each topic I cover will leverage my needed knowledge for another video that dependens on it. I hope you can guide me on the order of learning this material, thx

  • @piyushpathak1186
    @piyushpathak1186 Před 3 lety +3

    his free course is far better than the many paid courses of some giant educational company

  • @cheevavitchawalaworn7099
    @cheevavitchawalaworn7099 Před 4 lety +2

    Noooo!, this vid is super useful to me as a cs student. Can't thank u enough lol

  • @emilim720
    @emilim720 Před 4 lety +4

    I couldn't understand much because of the language difference but the graphics helped me, thanks
    sorry i don't have good english

  • @xyzzyx9357
    @xyzzyx9357 Před 4 lety +2

    WoW! Amazing explanation 👍👍👍.

  • @user-xz5nl5lk6h
    @user-xz5nl5lk6h Před 7 měsíci

    Excellent explanation

  • @Ef-sy4qp
    @Ef-sy4qp Před 3 lety

    Always, I Proud of You!!!n Thanks

  • @davidcrowell7043
    @davidcrowell7043 Před 4 lety +3

    (a+b)(c+d)-ac-bd (fully expands to)
    ac+ad+bc+bd-ac-bd (cancelling out terms to)
    ad+bc (the middle term of the upper expression)

  • @Dhakshith1189
    @Dhakshith1189 Před 3 lety

    Hey I'll try do my day to day math in this way and let you know!

  • @scitobot247
    @scitobot247 Před 3 lety +1

    Amazing explanation!:)

  • @bereketyisehak5584
    @bereketyisehak5584 Před 8 měsíci

    wowooo, i didn't expect to hear you speak amharic at the beginning. haha

  • @cw4608
    @cw4608 Před rokem

    When you opened the video in Arabic (I think), I was worried I wouldn’t be able to follow but would try anyway. Then you broke into English and I thought “good an instructor with a sense of humor”

  • @adityasrivastava8790
    @adityasrivastava8790 Před 3 lety +2

    Thank you so much John Legend!!!!

  • @piyushmajgawali1611
    @piyushmajgawali1611 Před 4 lety +4

    Do not think any algorithm is too hard for an interview
    Recently I interviewed for JP Morgan Chase Internship
    Longest Palindromic substring
    He wanted me to come up with the Manacher's algorithm
    Though I gave him a DP solutions and got through the round.

  • @eisbar9962
    @eisbar9962 Před 4 lety +1

    Thank you so much!

  • @ExamSolutions.e
    @ExamSolutions.e Před 2 lety

    thank you. your amharic is pretty good.

  • @luckydev3911
    @luckydev3911 Před 3 lety

    Looked it up after "reading" fast doubling for Fibonacci sequence

  • @pratyush2604
    @pratyush2604 Před 2 lety

    13:09 ad + bc can be number of length n + 1 too right ? so that will increase one addition. It should be alpha(n+1) then.
    16:30 it should be 3.alpha.n according to me. Not that it will make any difference tho,.

  • @abebe7017
    @abebe7017 Před 4 lety +3

    What! you speak my native language! Selam Selam! I really appreciate your great tutorials! Keep it up ! Gobez Anbesa!

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +5

      hahaha, ay, these are the comments I was aiming to generate. Yeah both my parents are 100% Ethiopian

    • @abebe7017
      @abebe7017 Před 4 lety +2

      @@BackToBackSWE Please give my best regards to your parents. They should be proud of you! I am an international student at Du** from Ethiopia. Hope to see you one day!

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      @@abebe7017 nice, we may meet haha

    • @Atm34
      @Atm34 Před 3 lety +1

      @@BackToBackSWE i had no idea! your Amharic is pretty good, and keep up the content as it has been really helpful to me as a CS student.

  • @AtlantaBill
    @AtlantaBill Před 2 lety

    Excellent pedagogy. I subscribed. However, the presentation leaves me wondering how someone can remember so much algebra while forgetting a simple language convention: that 'amount' is used with uncountable objects and 'number' is used with countable objects. "Number of levels/additions/multiplications", not "amount of levels/additions/multiplications". Now, this second quesion may show up MY ignorance. Why can't compiler optimization be more easily achieved for large-integer multiplication simply by using a stored table of logarithms broken into sections of increasing base numbers? Speaking of optimization, it took OurSewer and FireFox over a minute to post my second and fourth edited version.
    This might be interesting for someone: The name 'Karatsuba' can also be spelled 'Karatuba' in Japanese Romaji (Roman letters) because the syllable 'tu' is pronounced 'tsu'. The series is pronounced /ta chi tsu te to/ instead of /ta ti tu te to/. I had a Japanese boss who said "Fu?" on the telephone instead of "Who?", because in Romaji it's /ha hi fu he ho/, the pronunciation /hu/ being impossible in Japanese.

  • @karapponakoori
    @karapponakoori Před rokem

    breh, you got me there at the beginning xD

  • @bonbonpony
    @bonbonpony Před 3 lety

    13:13 What about the carry over to the next position after those four? We still have to add that one too, right?

    • @mikiaskebede3849
      @mikiaskebede3849 Před 3 lety

      The carry over additions are ignored when doing the run time analysis for this algorithm. Don't ask why.

  • @ektadhobley8019
    @ektadhobley8019 Před 3 lety +1

    Amazinggg video!

  • @asdfghjkl1770
    @asdfghjkl1770 Před 5 lety +2

    Wow you are amazing.
    Love from Bangladesh !

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +1

      wassup, love from the cornfields of America 🌽🌽

    • @asdfghjkl1770
      @asdfghjkl1770 Před 5 lety +1

      @@BackToBackSWE keep teaching us! I am 15 btw, learning ds and algo on my own , u just made it easy for me, thanks!

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +1

      @@asdfghjkl1770 Nice. Keep learning. Master what you do.
      Holy crap, 15 is so young (I'm about to be 20).
      You will be rewarded in life for being great at something economically valuable (i.e. programming and computer science understanding). (odd comment but it is kinda true)...it will serve as an entry way for you to do whatever you want later in life (I'm of course not at that point but yeah...it doesn't hurt to be really good at something valuable).
      So yeah...get really really good but try to stay human and meet your human needs (like don't isolate yourself in youth like I did)

    • @asdfghjkl1770
      @asdfghjkl1770 Před 5 lety +1

      @@BackToBackSWE Thank you so much for inspiring me ! I really love the process of learning programming , I started learning "how to code" in 2018, 16th nov and fall in love with programming. in my vacation , i guess i spend more than 10 hours a day just learning and writing code probably because it was fun, it was little bit addictive i guess..... my dream is to get a job at Google, and i will make my dream come true!

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +1

      @@asdfghjkl1770 Nice, I'd even aim higher. You don't just want to work somewhere, you probably have the ambition to change the world and help countless people.
      You can do that anywhere, anyway you see fit. Just stay open and stay sharp. And you will do great things. We all can.

  • @neogen23
    @neogen23 Před 4 lety +1

    Well, you lost me at 24.20. I don't get how you expand ad+bc the way you do. My algebra is quite rusty, so is this expansion a known algebraic identity for example? Can anyone elaborate?

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      distribute and perform the subtractions and it will be clear

  • @achyuthvishwamithra
    @achyuthvishwamithra Před 4 lety

    Why does the multiplication of (n/2)*(n/2) lead to n length number? We have considered a case where 99*99 would lead to 9801 (length 4). However, why did we not consider a number 10 * 10 = 100 (length 3)?
    Reference: czcams.com/video/-dfsxsiGoC8/video.html

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +1

      We are deriving an upper bound for work, 99*99 expresses that worst case. I should have been more precise, I don't remember what I said in this video exactly.

    • @achyuthvishwamithra
      @achyuthvishwamithra Před 4 lety

      @@BackToBackSWE Thank you, that makes sense :)

  • @akanksh422
    @akanksh422 Před 2 lety +1

    Great video! Watched it at 2x was super lucid still. But the dude scratching his itches at 2x wasn't smooth.

  • @factsheet4930
    @factsheet4930 Před 3 lety +1

    About 10 days after this video was published, an n*log(n) algorithm was discovered!

    • @justcode7326
      @justcode7326 Před 3 lety

      Can you share source

    • @factsheet4930
      @factsheet4930 Před 3 lety

      @@justcode7326 Just Google for integer multiplication in time O(nlogn)

  • @swastikchatterjee5838
    @swastikchatterjee5838 Před 3 lety +1

    i was about to close the video after the arabic.... Thanks to my patience that i waited for an extra two seconds....

  • @zq42
    @zq42 Před 3 lety +1

    bro thanks a lot

  • @rishabhgarg4942
    @rishabhgarg4942 Před 4 lety +1

    Hey, a doubt.
    For multiplying 2 numbers of length 4 each you said its 4*4 time, but for multiplying 2 n/2 length numbers, why you added them and said its n time? Why not n^2/4?

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      can you timestamp it? I made this video a while back so dont remember ti all

    • @rishabhgarg4942
      @rishabhgarg4942 Před 4 lety +1

      @@BackToBackSWE My bad, I got it now. Thanks for the super prompt reply!

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      @@rishabhgarg4942 oh, sweet

  • @user-oo2gz9ln8v
    @user-oo2gz9ln8v Před 4 lety +2

    thank goodness i skipped 20 minutes and saw algebra that i am miserable at learning now i know to close the tab and hate myself

  • @Konrad241111111
    @Konrad241111111 Před 4 lety +2

    Was so scared for the first few seconds LMAO

  • @CodeWithAb.
    @CodeWithAb. Před rokem

    😅በጣም እናመሰግናለን!

  • @ankitthakur9652
    @ankitthakur9652 Před 5 lety +2

    "You probably won't use this".... unless its on a 351 exam ;)

  • @taiwan.1
    @taiwan.1 Před 4 lety +5

    it is not useless... lol im being homeworked about this for a class.

  • @Levi-ug1fb
    @Levi-ug1fb Před 3 lety +1

    Me bouta use this for programming to make speedy calculator n stuff B)

  • @AnthonyFinix
    @AnthonyFinix Před 3 lety

    at 5:50 i was like.. gotcha

  • @DevChickenCode4Fun
    @DevChickenCode4Fun Před 4 lety +1

    I don't understand. Why is 2an ( 1an + 1an)? who can explain it help me?. Thank you!

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +1

      I dont remember the math to be honest shot this a while back

    • @DevChickenCode4Fun
      @DevChickenCode4Fun Před 4 lety

      @@BackToBackSWE I have understood it. Example x = 1234 => x1 = 12, x2 = 34 and y = 1234 => y1 = 12, y2 = 34
      10^4*x1y1 + 10^2(x1y2 + y1x1) + x2y2. I saw that x1y2 + y1x1 is 1an ( a is addition)
      10^4*x1y1 and x2y2 => xxxx0000 ( x1 = n/2, y1 = n/2 => x1y1 xxxx) then I only join xxxx0000 with x2y2 => xxxxxxxx then plus 10^2(x1y2 + y1x1)
      So xxxxxxxx then plus 10^2(x1y2 + y1x1) is 1an ( a is addition) and x1y2 + y1x1 is 1an ( a is addition)
      So We have 2an :) :)
      But What is Big O of this math?

  • @nebiyuelias1
    @nebiyuelias1 Před 4 lety +1

    Oh my god, this guy speaks Amharic! Are you habeshan?

  • @cocoarecords
    @cocoarecords Před 5 lety +1

    awesome

  • @nausea8101
    @nausea8101 Před 4 měsíci

    I need to learn math again

  • @Streamwalker1000
    @Streamwalker1000 Před 4 lety +1

    What a WASTE OF TIME... I found another site that just did an example multiplication without all the Math double talk...this was impossible to follow. I'll never come back here again.

  • @graaaaaa0
    @graaaaaa0 Před 3 lety

    You had me man....hahaha

  • @ET-Programming
    @ET-Programming Před 8 měsíci

    you can speak Amharic ?

  • @beatdown_kai1534
    @beatdown_kai1534 Před 2 lety

    lmfaoo finally a brother

  • @dongjunlee6500
    @dongjunlee6500 Před 4 lety +1

    i will just choose n^2....

  • @snowglider400
    @snowglider400 Před 3 lety +2

    Is that Amharic language ?

    • @BackToBackSWE
      @BackToBackSWE  Před 3 lety +2

      yeah lol my bad

    • @snowglider400
      @snowglider400 Před 3 lety

      @@BackToBackSWE nice language. I traveled to Adis multiple times and love it.

  • @christopherellis2663
    @christopherellis2663 Před rokem

    It's my, as in mü MY NY XI

  • @m.varunreddy7365
    @m.varunreddy7365 Před rokem

    brrrraaaahhhhhhhhhhhh
    thanks a lot
    new dimension unlocked

    • @BackToBackSWE
      @BackToBackSWE  Před rokem

      Happy 2023! Really glad to help 🎉 Do you know about our 5 Day Free DSA Mini Course? Check it out here - backtobackswe.com/

  • @sahilverma4979
    @sahilverma4979 Před 4 lety +1

    Content is nice but adds on adds are irritating!!

  • @christopherellis2663
    @christopherellis2663 Před rokem

    Pity you haven't demonstrated

  • @Abdurahman-zh6xz
    @Abdurahman-zh6xz Před 2 lety

    bro you scared me

  • @yoshi4980
    @yoshi4980 Před 5 lety +1

    why is it 3 multiplications? aren't the only multiplications you do are a*c and b*d?

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      For karatsuba? Karatsuba has 3 since we re-expressed the middle term. We re-expressed it into an expression that is the multiplication of 2 addition statements.

    • @yoshi4980
      @yoshi4980 Před 5 lety +1

      @@BackToBackSWE ah okay i see, thanks. also to confirm, an atomic multiplication/addition is simply the time it takes for a computer to do a basic multiplication/addition, so does that mean it's more or less the time a computer would take to multiply 2 one digit numbers?

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      @@yoshi4980 yeah, single digit multiplication or addition

  • @II_xD_II
    @II_xD_II Před 3 lety

    Whiteboard : Am i a joke to you

  • @swaw11
    @swaw11 Před 3 lety

    Its not useless

  • @melAKU699
    @melAKU699 Před 5 lety +4

    ere besmam ethiopiaw neh asdenegetikegn

  • @Parthsean
    @Parthsean Před 3 lety

    I did Computer Science to get away from math and here we are again smh... ** cries in math **

  • @instaminox
    @instaminox Před 4 lety +1

    Hahahaha nice joke

  • @telnet8674
    @telnet8674 Před 2 lety

    የዚ ግንባር ሚስጥር ተፈታ ለካ ሃበሻ ነህ lol