OK, sorry. Read More
You need to create a table of double value and at the same time keeping track of the value you need for the total sum. The maximum value of the double value will never go above the multiplication value you want it to be.
i.e. You want to do … Read More
Yes, that's just a concept of how to work it out in an iterative fashion. :) Need to adapt that to a recursive call by passing at least 2 variables to the call. If use a recursive call, no need dynamic arrays at all. :) Read More
let me try:
let as say you want to multiply 5 with 6.
upon first invocation of the method, add 5 to the first input param (that is five), and subtract one from 6. do this as long as the second param is bigger than 1. this, I believe, would … Read More
After I tried implementing it, the easiest way to deal with is to pass an integer array containing necessary arguments to the recursive call. That way, you could modify the value inside while going through the build & cumulate the result.
@bibiki, I am not sure how your method works. … Read More
@sobias, after I implemented it, I didn't need to build a table but keep tracking the current value and the value after double in one integer inside the array. The array I passed in as argument to the recursive call is size of 4 containing the multiplicand, the cumulative value … Read More
Sorry for a little late. @Bibiki, now I see that it is a brute-force algorithm. Yes, your algorithm is correct. :) However, I would have to disagree on "recursion is always slow" statement. The purpose of using recursion is usually for implementation (could be style or readability). The factor that … Read More
Since OP is going with the brute force approach, I guess there's no harm in posting this code....
It will multiply any two Java ints with a max of 31 recursions, vs 2 billion for the brute force solution.
<On second thoughts, maybe it's not a good idea to … Read More