Multiply Two Big Integers - Algorithms and Problem SolvingAlgorithms and Problem Solving
Given two big integers represented as strings, Multiplication them and return the production as string. For example, given a=2343324 and b=232232 then retiurn c = a*b = 23433242334323342 * 23223233232434324 = 544195652122144709711313995190808 We can see that the problem is trivial if we had given two small integers. But as the numbers can be really big we can't fit the operands or the results into primitive data types. So, we need to go back to old school process where we do the multiplication of two numbers by multiplying one number with each digit of another and shift the subsequent results to left by 1 digit, and then add all these intermediate results for each digit of second number. For example, let's consider a = 231 and b = 51. Then the elementary process of multiplication would be – 231 51 ---------- 231 <--- 231 * 1 = 231 1155x <--- 231 * 5 = 1155, then shift left by 1 position is equivalent to padding one zero to right i.e.Read full article from Multiply Two Big Integers - Algorithms and Problem SolvingAlgorithms and Problem Solving
No comments:
Post a Comment