Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Long multiplication and Karatsuba multiplication algorithms. This should be done in C++ A262: Lab 4 Program Speciications Implement the following algorithms. Put them in separate

image text in transcribedimage text in transcribedLong multiplication and Karatsuba multiplication algorithms. This should be done in C++

A262: Lab 4 Program Speciications Implement the following algorithms. Put them in separate functions. (You don't necessarily have to use arrays). You should include a counter in the algorithm that keeps count of the number of mathematical operations the algorithm requires. For the purposes of the counter, do not include the for loop operations. For example, this line of code: product[ai + bi 1] carry + alai] b[b.i] would require 5 operations (three additions, one subtraction, and one multiplication) Your program should run an experiment using these algorithms. Using two integers with 1, 2, 3, 4, and 5 digits, track how many operations each algorithm takes to complete the multiplication Then print out a table showi multiplied together, the product, how many operations the long multiplication took, and how many operations Karatsuba's algorithm took Submit a pdf of a screenshot of your program running ng your results. The table should have columns for the numbers you Algorithms Long Multiplication (base refers to the number base, i.e. base 10 for decimal, base 2 for binary) Reference: https://en.wikipedia.org/wiki/Multiplication algorithm Note these arrays start at 1 multiply (al1. .p] , b[i..q], base) // Operands containing rightmost digits at index 1 [1.. p+q] 1 to q; do //Allocate space for result product for b-i = // for all digits in b = carry = 0 for a-i = 1 to p; do //for all digits in a product[a i bi 1] carry + a[a_i] blb_i] carry - product [a i + b_i 1] / base product la-1 + b_1-1] -product [a_1 + b_1-1] mod base done product [b_i p +- carry // last digit comes from final carry done return product Karatsuba Multiplication Reference: https://en.wikipedia.org/wiki/Karatsuba.algorithm#Algorithm procedure karatsuba(num1, num2) if (num1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Describe the cash and accrual methods of accounting.

Answered: 1 week ago