Welcome to the VirtuQ Forums.
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Jan 2012
    Location
    Allahabad
    Posts
    184

    Factorial recursion program time

    Sir,

    I have made both programs of factorial, by recursion and iterative. But in the both cases the time of execution is same. So, why is the time of execution of both programs is same? The following attachment will show the time of execution of both functions:-

    Click image for larger version. 

Name:	recusion.jpg 
Views:	521 
Size:	61.4 KB 
ID:	52
    Click image for larger version. 

Name:	iterative.jpg 
Views:	545 
Size:	71.5 KB 
ID:	53

    Thank you

    Anon10087

  2. #2
    VirtuQ™ Moderator
    Join Date
    Jul 2011
    Location
    Bangalore, India
    Posts
    1,044
    Blog Entries
    2
    Anon10087,

    I want to take a look at your source code. Please point me to it in your home directory.

    Thanks,

    Anup

  3. #3
    Member
    Join Date
    Jan 2012
    Location
    Allahabad
    Posts
    184
    recursion program :- virtuqwork/prgc/functions/easy/ then myapp.c
    iterative program:- virtuqwork/prgc/fucntions/easy/ then iter.c


    Thanks

    Anon10087

  4. #4
    VirtuQ™ Moderator
    Join Date
    Jul 2011
    Location
    Bangalore, India
    Posts
    1,044
    Blog Entries
    2
    Anon10087,

    The indentation in the program was bad, I have fixed it. You can indent an area in vim by first selecting it (ESC followed by v, then arrow keys or h j k l for navigating) followed by pressing =

    On execution time, the results which you are getting are correct. However, you should also increase the value of input and see if you get any difference. Try to analyze as to why there is no difference. How many times is your function called in recursive implementation and how many times does the loop executed in iterative implementation. We do a much more detailed analysis of Fibonacci in Data Structures modules, but, you should be able to figure out that the number of times fib function is called is very high in the recursive version. You can find this out if you try to execute fib(5) using pen-and-paper.

    Cheers,

    Anup

  5. #5
    Member
    Join Date
    Jan 2012
    Location
    Allahabad
    Posts
    184
    Thanks sir

  6. #6
    VirtuQ™ Moderator
    Join Date
    Jul 2011
    Location
    Bangalore, India
    Posts
    1,044
    Blog Entries
    2
    Cool .

    Anup


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •