Git Product home page Git Product logo

multiplicationstudy's Introduction

Multiplication Case Study

Recently I came across a video regarding Karatsuba's Fast Multiplication Algorithm (https://www.youtube.com/watch?v=cCKOl5li6YM&t=788s) and decided to implement it in python. I followed the pseudocode from wikipedia regarding the algorithm (https://en.wikipedia.org/wiki/Karatsuba_algorithm) to implement my method.

To examine the effect that using Karatsuba's Fast Multiplication Algorithm has on real-time computations, I also implemented a standard elementary-school long multiplcation algorithm. To compare the two, I added operation counters within both methods that keep track of the respective number of addition and multiplication calculations being performed.

Finally, I simulated both algorithms being called 200 times for numbers ranging from 1 to upperBound (in my case 15) digits, averaged the operations performed and graphed them against the respective number of digits.

This resulted in the graph shown below that highlights the standard multiplication algorithm following the n^2 curve, while the Karatsuba multiplcation algorithm roughly follows an n^1.58 curve.

Plot

Note: The n^2 line overlaps the standard algorithm curve.

Note: The Karatsuba operation count may not be completely accurate which results in the respective line not following the n^1.58 curve as closely as I had hoped.

Usage

I've provided both a Python file and a JupyterNotebook with the standard, karatsuba, and simulation functions for testing/modifying purposes.

multiplicationstudy's People

Contributors

mugpand avatar

Watchers

 avatar

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.