Recursive Russian

Recursion just means solving a problem by reducing it to a smaller instance of the same problem.

``Reducing'' just means calling a subroutine. ``Smaller problem'' means different things, but the basic idea is that we are making measurable progress to the final answer.

int RussianRec(int a, int b)
//  implements Russian Peasant Algorithm recursively
{
  if (a == 0) return 0;
  else if ( 1 == a % 2) 
    return(b+ RussianRec(a >> 1, b) << 1);
  else
    return(RussianRec(a >> 1, b) << 1);
}


next up previous
Next: Discussion Up: RECURSION Previous: Review