Git Product home page Git Product logo

criss-cross-algorithm's Introduction

Criss-Cross Multiplication

Badge for test workflow

A 50-lines algorithm for multiplying large positive integers in string format. For numbers having less than 100 digits, it outperforms the Karatsuba algorithm by as much as 50%.

Read more about the algorithm in this post.

Installation

To install project:

git clone [email protected]:creme332/criss-cross-algorithm.git

Usage

Import mul.h in your program and initialise a Mul object as follows:

Mul Multiplier("9912", "54564");
Multiplier.vedic(); // 540838368

The Mul class has 3 methods for multiplication:

Method Description
basicVedic() A simpler and faster implementation of the criss-cross algorithm but is more limited since it uses basic arithmetic operators for addition and subtraction.
vedic() A version of basicVedic() that uses helper functions for adding and subtracting large string numbers.
karatsuba() Uses the Karatsuba algorithm for multiplication. Algorithm uses helper functions for adding and subtracting large string numbers.

Run benchmarks

To run benchmarks:

g++ benchmarks/main.cpp benchmarks/timer.cpp src/mul.cpp -W
./a.out

A folder output will be created inside the benchmarks folder. This new folder will contain the following files:

File name Content
input.txt A list of multiplicands and multipliers which were generated during runtime.
time.txt Each line contains 2 values representing the time taken for vedic and karatsuba algorithms respectively
product.txt Each line contains 2 values representing the product calculated by vedic and karatsuba algorithms respectively. These values should be same.

Run tests

g++ test_runner.cpp tests/tests.cpp src/mul.cpp -W
./a.out

To-do

  • Use Google Benchmark for benchmarks

References

criss-cross-algorithm's People

Contributors

creme332 avatar

Watchers

 avatar  avatar

Forkers

bastian-polewka

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.