NicolaLino / karatsubaMultiplication

Karatsuba Algorithm written in Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

karatsuba Multiplication

The Karatsuba algorithm is a fast multiplication algorithm. Karatsuba multiplication algorithm is named after the Russian mathematician Anatoly Karatsuba. It uses a divide and conquer approach that gives it a running time improvement over the standard “grade-school” method. Read on for Python implementations of both algorithms and a comparison of their running time.

Example image

image

Where a,b,c,d are n/2 digit numbers.

image

Here’s Karatsuba’s algorithm:

  1. Break the two integers x and y into a, b, c and d as described above
  2. Recursively compute ac
  3. Recursively compute bd
  4. Recursively compute (a + b)(c + d)
  5. Calculate (ab + bc) as (a + b)(c + d) – ac – bd
  6. Let A be ac with n zeros added to the end
  7. let B be (ab + bc) with half n zeros added to the end
  8. The final answer is A + B + bd

for more information https://en.wikipedia.org/wiki/Karatsuba_algorithm

About

Karatsuba Algorithm written in Python.


Languages

Language:Python 100.0%