Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2007 VBA Programming Problem Set

Status
Not open for further replies.

tommylam

Technical User
Nov 9, 2010
1
GB
I am having a problem trying to answer this question. I just started VBA in Excel and its been very difficult grasping every detail so if anyone can give some advise i will be more than grateful .

The question is :

Implementing your Fibonacci algorithm or The Magic of Recursion
Implement the Fibonacci algorithm by iteration, i.e., by using some counter variable and temporary variables to keep track of where you are in the loop.
Write a standard Function for this purpose and then write a normal spreadsheet with the rst 21 elements of the sequence, zero inclusive, in the sheet Fibonacci of the aforementioned workbook.

Now take a look at the following code:

Function Fibonacci(n As Long) As Long
If n = 0 Or n = 1 Then
Fibonacci = 1
Exit Function
End If
Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
End Function


Do you think it will work? Does it really? Test it by displaying the results of both
functions side-by-side in the spreadsheet, i.e., in one column you will have the Fibonacci
sequence calculated by your iterative function and in the other the Fibonacci sequence
calculated by recursion. Use standard Excel techniques to create these columns, i.e.,
use both formulas as normal Excel ones. What's the index of the largest element you
can calculate with the recursive function above? Why is that? What change(s) in the
code do you propose to allow for larger elements of the sequence to be calculated?
This question illustrates the magic of recursion. Recursion is a powerful programming technique that helps us solve many problems very quickly, albeit not necessarily in the most excient way. Recursion is an example of \divide and conquer" techniques, which
are known for not being computationally excient.

PART B : Also you have to document the marked decrease in performance of the recursive Fibonacci sequence function when compared with its iteration cousin. Create a Sub that lists the di erence in execution time of both functions { recursion vs. iteration { when n = 1 : : : 50. Plot the di erence in a (n x time) Excel chart. You don't need to write a macro to create the chart.



Thank you For any Tips
 


So what course are you taking?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top