0

Hi This a very generic question. I Want to know can whether every Iterative method(using loops) can be done using recursion?

imp25
  • 2,277
  • 14
  • 23
user2059287
  • 15
  • 1
  • 7
  • 1
    YES !! :) Already answered here - http://stackoverflow.com/questions/2093618/can-all-iterative-algorithms-be-expressed-recursively – Pranay Agrawal Feb 01 '14 at 19:32

3 Answers3

0

I Want to know can whether every Iterative method(using loops) can be done using recursion?

Yes, see Church–Turing thesis, it proves this.

Useful links:

Maroun
  • 91,013
  • 29
  • 181
  • 233
0

Yes. Some great explanations can be found here.

Benjamin Bini
  • 301
  • 4
  • 13
0

Here is a generalized iterative function :-

for(int i=0;i<n;i++) {

   doSomething(i);

}

Here is equivalent recursive function :-

recfunc(int i,int n) {

  if(i<n) {

       doSomething(i); 
       recfunc(i+1,n);

  }

}
Vikram Bhat
  • 5,972
  • 3
  • 18
  • 19