|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Implementation of the Karatsuba algorithm for fast multiplication More...
#include <cassert>#include <cstring>#include <iostream>#include <vector>Namespaces | |
| namespace | divide_and_conquer |
| for std::vector | |
| namespace | karatsuba_algorithm |
| Functions for the Karatsuba algorithm for fast multiplication | |
Functions | |
| std::string | divide_and_conquer::karatsuba_algorithm::addStrings (std::string first, std::string second) |
| Helper function for the main function, that implements Karatsuba's algorithm for fast multiplication. More... | |
| int64_t | divide_and_conquer::karatsuba_algorithm::karatsuba_algorithm (std::string str1, std::string str2) |
| The main function implements Karatsuba's algorithm for fast multiplication. More... | |
| static void | test () |
| Self-test implementations. More... | |
| int | main () |
| Main function. More... | |
Implementation of the Karatsuba algorithm for fast multiplication
Given two strings in binary notation we want to multiply them and return the value Simple approach is to multiply bits one by one which will give the time complexity of around O(n^2). To make it more efficient we will be using Karatsuba' algorithm to find the product which will solve the problem O(nlogn) of time.
| std::string divide_and_conquer::karatsuba_algorithm::addStrings | ( | std::string | first, |
| std::string | second | ||
| ) |
Helper function for the main function, that implements Karatsuba's algorithm for fast multiplication.
| first | the input string 1 |
| second | the input string 2 |
| int64_t divide_and_conquer::karatsuba_algorithm::karatsuba_algorithm | ( | std::string | str1, |
| std::string | str2 | ||
| ) |
The main function implements Karatsuba's algorithm for fast multiplication.
| str1 | the input string 1 |
| str2 | the input string 2 |
| int main | ( | void | ) |
|
static |
Self-test implementations.