comp-think / 2019-2020

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2019/2020).
Other
12 stars 3 forks source link

Lecture "Algorithms", exercise 3 #6

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

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.

arcangelo7 commented 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.

Esercizio3-1

arcangelo7 commented 4 years ago

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.

Esercizio3-2

FrancescoFernicola commented 4 years ago

Representation of the first algorithm Exercise 3 Algorithm 1

marcograsso commented 4 years ago

Algorithm1 - flowchart

exflowfib

Algorithm2 - flowchart

fibo2floc

ariannamorettj commented 4 years ago

First Fibonacci algorithm representation (Flowchart) flow3

Second Fibonacci algorithm representation (Flowchart) flow4

noreanystrom commented 4 years ago

Task 3 Algorithms Task 3_2 Algorithms

ariele-santello commented 4 years ago

Representation of the first Fibonacci algorithm Untitled Diagram

ariele-santello commented 4 years ago

Representation of the second Fibonacci algorithm second Diagram

Prope95 commented 4 years ago

Flowchart of the first Fibonacci sequence algorithm

Fibonacci's serie algorithm

elisasilvad commented 4 years ago

1st definition Excercise 2 3 1

2nd definition Excercise 2 3 2 But I have a doubt with the second one

sntcristian commented 4 years ago

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

a809 commented 4 years ago

First Fibo 1

a809 commented 4 years ago

Second FIBO 2

aschimmenti commented 4 years ago

Fibonacci function, following the first natural language definition. Fibonacci function, following the second natural language definition.

arimuti commented 4 years ago

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.

arimuti commented 4 years ago

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

essepuntato commented 4 years ago

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:

  1. 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.

  2. 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").