Open essepuntato opened 4 years ago
This is the representation of the first Fibonacci algorithm, that which says:
The function for calculating the nth Fibonacci number takes as input an integer “n”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is less than or equal to 2, then 1 is returned. Otherwise, in all the other cases, associate the value “1” to two distinct variables “a” and “b”. Then, repeat the following operations indefinitely. Set the variable “c” as the sum of “a” plus “b”. If “n” is less than or equal to “3” then return “c”, otherwise assign the value of “b” to “a” and the value of “c” to “b”, and finally decrease the value of “n” by 1 before repeating.
This is the representation of the second Fibonacci algorithm, that which says:
The function for calculating the nth Fibonacci number takes as input an integer “n”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is equal to 1, then 1 is returned. Otherwise, return the sum of the same function with “n-1” as input and still the same function with “n-2” as input.
Representation of the first algorithm
First Fibonacci algorithm representation (Flowchart)
Second Fibonacci algorithm representation (Flowchart)
Representation of the first Fibonacci algorithm
Representation of the second Fibonacci algorithm
Flowchart of the first Fibonacci sequence algorithm
1st definition
2nd definition
But I have a doubt with the second one
First representation: https://drive.google.com/file/d/16IG8o-BR04ahLcUuwFQuKY-g5KTzY043/view?usp=drivesdk Second representation: https://drive.google.com/file/d/16F-4gBz5ySjHuTkxBqxpzLvLLzkSlVxR/view?usp=drivesdk
First
Second
https://github.com/comp-think/2019-2020/files/3742906/Untitled.Diagram.pdf The function for calculating the n th Fibonacci number takes as input an integer “n”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is less than or equal to 2, then 1 is returned. Otherwise, in all the other cases, associate the value “1” to two distinct variables “a” and “b”. Then, repeat the following operations indefinitely. Set the variable “c” as the sum of “a” plus “b”. If “n” is less than or equal to “3” then return “c”, otherwise assign the value of “b” to “a” and the value of “c” to “b”, and finally decrease the value of “n” by 1 before repeating.
https://github.com/comp-think/2019-2020/files/3743011/Fib2.pdf
The function for calculating the n th Fibonacci number takes as input an integer “n”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is equal to 1, then 1 is returned. Otherwise, return the sum of the same function with “n-1” as input and still the same function with “n-2” as input.
I'm not sure my flowchart is right because I did not define the F function at the beginning
Hi all,
First of all, thanks for your incredible work. A few suggestions here – I will recall then in the lecture in a few minutes:
Once developed the flowchart, it is important to test it so as to see if it will return some unexpected values on some input. Please, try to run all the flowchart you have proposed with the following input numbers: 0, 1, 3, 7. See if all the flowcharts return the right output value for each of the inputs.
If you need to use again the algorithm itself in the second diagram, then associated a label to the algorithm or use a clear sentence that clarifies what is happening (e.g. "executing this algorithm using n-1 as input").
The previous lecture notes, entitled “Introduction to Computational Thinking”, illustrate two different algorithms, expressed in natural language, for implementing the Fibonacci function. Create two distinct flowcharts to implement both of them.