Skip to content

Commit

Permalink
Updated README File
Browse files Browse the repository at this point in the history
Updated README File
  • Loading branch information
HardevKhandhar committed Mar 4, 2020
1 parent 9824e05 commit 54bfcd2
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions Fibonacci_Number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ It is one of the most famous formulas in mathematics defined by the linear recur
F(n) = F(n - 1) + F(n - 2)
```

So, the Fibonacci Sequence becomes
```
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
```
and so on!

## Algorithm
```
Step 1: START
Expand All @@ -38,7 +32,8 @@ Step 5: Print a and b
Step 6: Repeat until i < n
fib ← a + b
print fib
a ← b, b ← fib
a ← b,
b ← fib
i ← i + 1
Stop 7: STOP
```
Expand All @@ -56,15 +51,12 @@ IF n is less than 1
IF n is equal to 1
DISPLAY 1
IF n is equal to 2
DISPLAY 1, 1
IF n is greater than 2
IF n is greater than or equal to 2
a = 1,
b = 1,
DISPLAY a, b
REPEAT FOR 0 to n
REPEAT LOOP from 2 to n
Fib = a + b
DISPLAY Fib
a = b
Expand Down Expand Up @@ -123,7 +115,7 @@ Hence the next number in the sequence above will be 21 + 34 = 55
```

## Complexity Analysis
## Different Approaches To Solve Fibonacci Sequence

### Approach 1: Recursion

Expand All @@ -139,11 +131,6 @@ F(n) = F(n - 1) + F(n - 2)

<img src="https://i.stack.imgur.com/QVSdv.png">


**Time Complexity: O(2<sup>N</sup>)**

This is probably the slowest way to solve the Fibonacci Sequence Problem since it takes exponential time. The amount of operations needed, for each level of recursion, grows exponentially as the depth approaches N.

### Approach 2: Bottom-Up Approach Using Memorization

**Algorithm**
Expand All @@ -153,10 +140,6 @@ This is probably the slowest way to solve the Fibonacci Sequence Problem since i
- Use this array as a reference to the 2 previous numbers to calculate the current Fibonacci number.
- Once we reach the last number, return it's Fibonacci number.

**Time complexity : O(N)**

Each number, starting at 2, up to and including N, is traversed, computed and then stored for O(1) access later on.

### Approach 3: Iterative Approach

**Algorithm**
Expand All @@ -172,9 +155,16 @@ Each number, starting at 2, up to and including N, is traversed, computed and th
- End Loop
- END

**Time complexity: O(N)**
## Complexity Analysis

**Approach 1: Recursion**
- Time Complexity: O(2<sup>N</sup>)

**Approach 2: Bottom-Up Approach Using Memorization**
- Time complexity : O(N)

Each value from 2 to N will be visited at least once. The time it takes to do this is directly proportionate to N where N is the Fibonacci Number we are looking to compute.
**Approach 3: Iterative Approach**
- Time complexity: O(N)

### Concluding Results

Expand Down Expand Up @@ -234,8 +224,6 @@ Similar analysis can be done for last digits as well.

<img src="https://i.pinimg.com/originals/ea/f1/73/eaf1738ff446ea088a4c7bf84a4b88fe.jpg" width=290>



- A one dimensional optimization technique method called the **Fibonacci Search** techniques uses Fibonacci Numbers.

- The Fibonacci numbers are also an example of a complete sequence.
Expand Down Expand Up @@ -264,4 +252,4 @@ The pattern and the way in which the seeds are packed on the flower heads seem t

### Fibonacci Sequence At A Glance

<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRtKMuS-fG5QYquaDo9Zk-wpLb7azf_dRiyTWABxegy9HH2KAPQ">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRtKMuS-fG5QYquaDo9Zk-wpLb7azf_dRiyTWABxegy9HH2KAPQ">

0 comments on commit 54bfcd2

Please sign in to comment.