0

I have a problem and I did solved it using simple loops. But the program have tight time bounds. Will I be able to get better time of execution using recursive call of some function??

long int calcMis(char *string,int i, int j,int len)
{
     long int mis=0;
     for(int k=0;k<len;k++)
     {
             if((mis+len-k)<=max)
                 return mis;

             if(string[i+k]!=string[j+k])
                mis++;

             if(mis>max)
                 return -1;
     }
     return mis;
}
ranger
  • 301
  • 1
  • 3
  • 10
  • 2
    May be, if you're willing to show some codes – P0W Aug 09 '13 at 15:49
  • Can you post your code so that we can do an iterative analysis of your algorithm? It will help us communicate to you on why you are receiving these problems. The likely hood is you are creating an algorithm that performs in some ridiculous run time (such as 2^n). – Jacob Pollack Aug 09 '13 at 15:50
  • hard to tell without knowing anything about the problem.... – Ingo Leonhardt Aug 09 '13 at 15:50
  • recursion isnt a magic spell, you need to look at your loop body and figure out what is taking longer than it should, and optimize it. or at a higher level, improve your algorithm – Karthik T Aug 09 '13 at 15:52
  • Recursion involves a function call which typically uses more resources (time, storage) than staying in the same program and iteratively looping. – JackCColeman Aug 09 '13 at 15:57
  • @KarthikT: code included in question – ranger Aug 09 '13 at 16:59
  • @JackCColeman:code included in question – ranger Aug 09 '13 at 17:01

1 Answers1

1

There is a lot of threads about this subject already. Is recursion ever faster than looping? or Why is recursion in python so slow? are yielded in the first google search page...

Community
  • 1
  • 1
Phil
  • 294
  • 2
  • 11