Problem 2.19. How much time is required to add or subtract two large integers of size m and n respectively? Sketch the appropriate algorithm. Solution For the large integers, they can not be accomodated in the permitted range of 32 bits of standard integer(Exact size depends on the system and environment). So to add two very large numbers, we can keep them in form of string and then process them from right side, one character at a time. Below is the algorithm: Suppose we have got two nos 125372 432 1. Take two strings s1 and s2. 2. copy 125372 in s1, and 432 in s2 3. Compute the length diff: abs(length(s1) - length(s2)). Left pad the small string with zeroes so that size of both the strings are same. Lets assume length is n now. 4. Create a result string of (n+1) character, as the addition might produce a carry on the last. 5. Now start from the right most digit of both nos. Compute the int value of single digit in both nos as shown below. To get the int value of a digit, we subtract \'0\' in from of character from the String chacter, so that we get exact digit. 6. Now sum both these digits and put the result\'s unit bit in resultant string at ith position. You might get an carry in this step, which you need to remember, when you go to process the (i-1)th digit of the nos. For( i=n; i >= 1; i-- ) { // TO find out the digit at iTh pos in s1 in number format from character format int n1 = s1.charAt(i) - \'0\' int n2 = s2.charAt(i) - \'0\' int carry = ((n1+n2)>=10) ? 1: 0; result[i+1] = \'0\' + ((n1+n2)%10); //only put unit digit in result string, that too in form of character } 7. Keep doing the above steps for all the n digits. Now you may get a overall carry at the last step, which you need to keep on result[0] pos. And your reslt string is prepared with the sum. Similary can be done for subtraction also..