Lecture "Algorithms", exercise 3
essepuntato opened this issue · 19 comments
essepuntato commented
The previous chapter, entitled “Introduction to Computational Thinking”, illustrates two different algorithms, expressed in natural language, for implementing the Fibonacci function. Create two distinct flowcharts to implement both of them.
ManueleVeggi commented
martasoricetti commented
MaddaGh commented
AmeliaLamargese commented
rahak commented
The first natural language instructions of Fibonacci function:
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 until a value is returned.
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.
Flowchart version :
The second natural language instructions of Fibonacci function :
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.
As I have mentioned earlier I couldn't actually understand the quoted part of the instructions in the second version still trying.
Pablo751 commented
olgagolgan commented
NoraPs commented
angstigone commented
giorgimariachiara commented
giorgimariachiara commented
elizastuglik commented
chloeppd commented
ManuSrivastava1 commented
sanyuezoe commented
RebeccaJillianBeattie commented
CarmenSantaniello commented
francescabudel commented
Marethyu6 commented