Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Express the fast multiplication algorithm in pseudocode.

Short Answer

Expert verified

FastmultiplyA1,B1+2n fastmultiply A1-A0,B0-B1+2n+1fastmultiplyA0,B0 return answer.

Step by step solution

01

Fast Multiplication definition

The algorithm for fast multiplication of integers is based on the fact that abcan be rewritten as:ab=(22n+2n)A1B1+2n(A1-A0)(B0-B1)+(2n+1)A0B0.

02

Use Fast Multiplication and write the pseudocode

In the algorithm "fastmultiply", the input is two nonnegative integers.

Procedure is: fastmultiply ( a,bnonnegative integers) If the two integers are 0or 1, then multiply the integers directly.

Divide the two integers by 2nand their remainders, where nis half the length of the integer in binary form. if a1and b1then return a,belse

n:=max(length(a),length(b))2A1:=a/2nB1:=b/2nA0:=a-2nA1B0:=b-2nB1

Assume that A1,A0,B1,B0all have length n: add 0's in front of the number if necessary.

Next use the fact that a,bcan be rewritten as

ab=22n+2nA1B1+2nA1-A0B0-B1+2n+1A0B0answer ab=22n+2nfastmultiply A1,B1+2nfastmultiply A1-A0,B0-B).

Combine these steps to obtain procedure fast multiply (a,b:nonnegative integers with length neach if a1and b1then return abelse

n:=max(length(a),length(b))2A1:=a/2nB1:=b/2nA0:=a-2nA1B0:=b-2nB1

Answer:=22n+2n

FastmultiplyA1,B1+2n fastmultiply A1-A0,B0-B1+2n+1 fastmultiply A0,B0return answer.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free