Giter VIP home page Giter VIP logo

divide-conquer-multiplication's Introduction

divide-conquer-multiplication

multiplication of long numbers.

#Complexity of Karatsuba To analyze the complexity of the Karatsuba algorithm, consider the number of multiplications the algorithm performs as a function of nn, M(n)M(n). Recall that the algorithm multiplies together two nn-bit numbers. If n=2^kn=2 k for some kk, then the algorithm recurses three times on \frac{n}{2} 2 n ​ -bit number. The recurrence for this is

M(n) = 3M\left(\frac{n}{2}\right). M(n)=3M( 2 n ​ ). This takes care of the multiplications required for Karatsuba--now to consider the additions and subtractions. There are O(n)O(n) additions and subtractions required for the algorithm. Therefore, the overall recurrence for the Karatsuba algorithm is[2]

T(n) = 3T\left(\frac{n}{2}\right) + O(n). T(n)=3T( 2 n ​ )+O(n).

Using the master theorem on the above recurrence yields that the running time of the Karatsuba algorithm is \Theta\big(n^{\log_2 3}\big)\approx \Theta\big(n^{1.585}\big).Θ(n log 2 ​ 3 )≈Θ(n 1.585 ).

The Schönhage–Strassen algorithm and the Toom–Cook algorithm are other popular integer multiplication algorithms. The Toom-Cook algorithm is faster, more generalized version of the Karatsuba algorithm that runs in \Theta\left(n^{\frac{\log 5}{\log 3}}\right) \approx \Theta\big(n^{1.465}\big)Θ(n log3 log5 ​

)≈Θ(n 1.465 ).[3] The Schönhage–Strassen algorithm is faster than both Karatsuba and Toom-Cook for very large nn \big((on the order of n > 2^{2^{15}}\big)n>2 2 15

) and runs in O(n \log n \log \log n)O(nlognloglogn).[4]

See Also

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.