[Verse 1] When numbers get massive and multiplication's slow There's a clever algorithm that'll steal the show Karatsuba's the name, divide and conquer's the game Split your digits in half, reduce the computational strain Traditional method takes n-squared time to complete But this Russian technique makes the process more sweet Take your number A-B, and your number C-D Where A and C are high, B and D are low, you see [Chorus] Split and multiply, three times not four Karatsuba's magic opens up the door A-C times ten-squared plus A-plus-B times C-plus-D Minus A-C minus B-D, that's the key Split and multiply, watch the time decrease From quadratic down to log-linear peace [Verse 2] Let me break it down with numbers, make it crystal clear Take five-six-seven-eight times one-two-three-four here Split them both in half, fifty-six and seventy-eight Twelve and thirty-four, now calculate their fate First multiplication: fifty-six times twelve Second one: seventy-eight plus fifty-six, delve Into ninety-six times forty-six, that's our middle term Third: seventy-eight times thirty-four, watch the pattern firm [Chorus] Split and multiply, three times not four Karatsuba's magic opens up the door A-C times ten-squared plus A-plus-B times C-plus-D Minus A-C minus B-D, that's the key Split and multiply, watch the time decrease From quadratic down to log-linear peace [Bridge] Recursive calls stack up like building blocks Each level cuts the problem, beating traditional clocks Base case hits when digits get too small Switch to grade school method, answer them all The beauty lies in asymptotic gain When input size grows, we break the chain Of exponential growth, efficiency's our aim Three multiplies per level, that's Karatsuba's claim [Verse 3] Implementation-wise, pad your numbers with zeros Handle odd-length digits like computational heroes Recursion depth is log-n, memory overhead's light Threshold optimization makes performance tight For small numbers stick to basic multiplication But when dealing with cryptographic calculation Million-digit integers, polynomial arithmetic too Karatsuba's your weapon, tried and true [Chorus] Split and multiply, three times not four Karatsuba's magic opens up the door A-C times ten-squared plus A-plus-B times C-plus-D Minus A-C minus B-D, that's the key Split and multiply, watch the time decrease From quadratic down to log-linear peace [Outro] From Moscow nineteen-sixty, this algorithm came Revolutionizing how we play the multiplication game So remember the formula when big numbers collide Karatsuba multiplication, let efficiency be your guide
← Strassen's matrix multiplication | Closest pair of points →