Fibonacci (2024)

CSSE 221: Fibonacci, Tail-Recursion and Efficiency

In this exercise, you will learn about recursion and tail-recursion by implementing regular and tail-recursive versions of the fibonacci function. You will explore the difference in running time of the tail-recursive and recursive versions.

  1. Create a new Eclipse project and name it Fibonacci.
  2. Use Team → Share Project to attach your Fibonacci project to your individual SVN repository for this course.
  3. The mathematical function Fibonacci is defined as follows: Fibonacci (1)
  4. Part 1: Standard Fibonacci is inefficient

  5. Implement a recursive version of fib which returns the nth Fibonacci number.
  6. Write a main method that runs your method for n = 10, 20, 30, 40, and 50 and prints well-labeled output. Here are the expected answers:
    • fib(10) = 55
    • fib(20) = 6,765
    • fib(30) = 832,040
    • fib(40) = 102,334,155
    • fib(50) = 12,586,269,025
  7. Modify your code to count the number of recursive calls used to calculate each value. You'll probably want to use a static field to store the count. Here are some expected answers, though depending on your implementation the number of steps might vary:
    • The 10th Fibonacci number is 55 in 177 steps.
    • The 20th Fibonacci number is 6765 in 21891 steps.
    • The 30th Fibonacci number is 832040 in 2692537 steps.
    • The 40th Fibonacci number is 102334155 in 331160281 steps.
    • The 50th Fibonacci number is 12586269025 in 40730022147 steps.
  8. Part 2: Tail-recusive Fibonacci is much more efficient!

  9. Now manually calculate and write down the first ten numbers in the Fibonacci sequence.
  10. Implement a tail-recursive version of the fibonacci function which returns the nth Fibonacci number. Keep these hints in mind:
    • In order to develop an algorithm, think about what you did in order to determine the next number in the sequence manually.
    • You will need to create a helper method.
    • You will need to keep track of the prior two numbers in order to determine the next number in the sequence: these become parameters in the helper method.
    • The tail-recursive helper method only calls itself once, which is why it is more efficient.
  11. Test your tail-recursive version for n = 10, 20, 30, 40, 50, 100, and 1000.
  12. Modify your code to count the number of recursive calls used to calculate each value. You'll probably want to use a static field to store the count. Here are some expected answers, though depending on your implementation, the number of steps might vary:
    • The 10th Fibonacci number is 55 in 10 steps.
    • The 20th Fibonacci number is 6765 in 20 steps.
    • The 30th Fibonacci number is 832040 in 30 steps.
    • The 40th Fibonacci number is 102334155 in 40 steps.
    • The 50th Fibonacci number is 12586269025 in 50 steps.
  13. Commit your changes to be graded.
Fibonacci (2024)

FAQs

Do professional traders use Fibonacci? ›

Every foreign exchange trader will use Fibonacci retracements at some point in their trading career. Some will use them just some of the time, while others will apply them regularly.

What is 0.618 Fibonacci? ›

The 0.618 Fibonacci retracement level tends to act as a capitulation price level where anyone who was going to stop-out of a position has been stopped out or has given up. This is what makes the 0.618 Fibonacci retracement level a prime entry point. The 0.382 is the nominal pullback level to consider on pullbacks.

How to solve the Fibonacci sequence? ›

The Fibonacci sequence formula deals with the Fibonacci sequence, finding its missing terms. The Fibonacci formula is given as, Fn = Fn-1 + Fn-2, where n > 1. It is used to generate a term of the sequence by adding its previous two terms.

What is the success rate of Fibonacci? ›

Our Fibonacci Testing Results
Fibonacci LevelsSuccess Rate
61.821%
10016%
Overall37%
Failure Rate63%
3 more rows
May 4, 2024

What is the best timeframe to use Fibonacci? ›

The best time frame to identify Fibonacci retracements is a 30-to-60-minute candlestick chart, as it allows you to focus on the daily market swings at regular intervals.

What is the golden rule of Fibonacci retracement? ›

As per the Fibonacci retracement theory, after the upmove one can anticipate a correction in the stock to last up to the Fibonacci ratios. For example, the first level up to which the stock can correct could be 23.6%. If this stock continues to correct further, the trader can watch out for the 38.2% and 61.8% levels.

Is Fibonacci retracement a good strategy? ›

That said, many traders find success using Fibonacci ratios and retracements to place transactions within long-term price trends. Fibonacci retracement can become even more powerful when used in conjunction with other indicators or technical signals.

What is the best Fibonacci golden ratio? ›

What is the Fibonacci sequence? The golden ratio of 1.618 – the magic number – gets translated into three percentages: 23.6%, 38.2% and 61.8%.

What is the golden ratio Fibonacci? ›

The golden ratio, also known as the golden number, golden proportion, or the divine proportion, is a ratio between two numbers that equals approximately 1.618. Usually written as the Greek letter phi, it is strongly associated with the Fibonacci sequence, a series of numbers wherein each number is added to the last.

What is the golden ratio in real life? ›

For example, the measurement from the navel to the floor and the top of the head to the navel is the golden ratio. Animal bodies exhibit similar tendencies, including dolphins (the eye, fins and tail all fall at Golden Sections), starfish, sand dollars, sea urchins, ants, and honey bees.

Where is the Fibonacci sequence used in real life? ›

The Fibonacci sequence, also known as the golden ratio, is utilized in architectural designs, creating aesthetically pleasing structures. In engineering and technology, Fibonacci numbers play a significant role, appearing in population growth models, software engineering, task management, and data structure analysis.

What is the Fibonacci rule? ›

The Fibonacci sequence is the series of numbers where each number is the sum of the two preceding numbers. For example, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, … Mathematically we can describe this as: xn= xn-1 + xn-2.

Was Fibonacci forgotten for 400 years? ›

He Was Forgotten for 400 Years

In Italy, he was even regarded as an icon. However, after he passed away circa 1240, his name eventually disappeared from the pages of any writing on the history of mathematics. It wasn't until the late 18th century that his name finally resurfaced.

What is the best Fibonacci setup? ›

The most popular Fibonacci retracements are 61.8% and 38.2%. Note that 38.2% is often rounded to 38%, and 61.8 is rounded to 62%.

Why is Fibonacci so famous? ›

Fibonacci brings the numerals 0-9 to Europe and identifies a number sequence that exists in nature. He solved many problems with algebra for the first time using the shortened versions of numbers that used the Hindu-Arabic numerals. He wrote several books that studied algebra, geometry, and trigonometry.

Is Fibonacci a good trading strategy? ›

That said, many traders find success using Fibonacci ratios and retracements to place transactions within long-term price trends. Fibonacci retracement can become even more powerful when used in conjunction with other indicators or technical signals.

Do institutional traders use Fibonacci? ›

Fibonacci retracements are accepted and used by many traders, including some who trade for large institutions and hedge funds.

Can you use Fibonacci for day trading? ›

Fibonacci retracements are derived from Fibonacci sequences. Retracement levels are 23.6%, 38.2%, 61.8%, and 78.6%. In day trading these retracement levels help define levels between highs and lows where prices may stall or reverse.

What type of charts do professional traders use? ›

Traders use candlestick charts to determine possible price movement based on past patterns. Candlesticks are useful when trading as they show four price points (open, close, high, and low) throughout the period the trader specifies.

Top Articles
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 6475

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.