Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Problem 1: Optimise The Code

View previous topic View next topic Go down

Problem 1: Optimise The Code

Post  Nishchal on Sun May 23, 2010 1:09 pm

Following is a very general code used in C (recursive Factorial). Your goal is to optimise the code so it could run faster with proper reasoning.

Programming language :- C
Type:- Optimisation for speed


Code:

int Function(int x)
{
      int p;
      if(p==1)
      {
            return(1);
      }
      else
      {
              p=x*function(x-1);
              return(p);
        }
}
avatar
Nishchal
The Last Don

Posts : 55
Join date : 2010-05-22
Age : 32

View user profile http://gpdckullubca.forum-motion.com

Back to top Go down

Re: Problem 1: Optimise The Code

Post  Nishchal on Tue Jun 01, 2010 6:39 pm

HINT:- since the code is to be optimise for speed. Just check where is the performence loss occuring in the code.
avatar
Nishchal
The Last Don

Posts : 55
Join date : 2010-05-22
Age : 32

View user profile http://gpdckullubca.forum-motion.com

Back to top Go down

Re: Problem 1: Optimise The Code

Post  Nishchal on Sat Jun 05, 2010 11:52 pm

Optimisation 1:- The int p can be declared to be static, since it will be created everytime the function calls itself. By declaring it to be static, it will last till the function ends(with program) and will save u the time/memory for creation of 'p' everytime function is called.
avatar
Nishchal
The Last Don

Posts : 55
Join date : 2010-05-22
Age : 32

View user profile http://gpdckullubca.forum-motion.com

Back to top Go down

Re: Problem 1: Optimise The Code

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum