comp-think / 2021-2022

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. 2021/2022).
17 stars 9 forks source link

Lecture "Algorithms", exercise 3 #7

Open essepuntato opened 2 years ago

essepuntato commented 2 years ago

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 2 years ago

I hope I managed to correctly translate the two algorithms in these two flowcharts.

This flowchart represents the first algorithm:

Schermata 2021-10-16 alle 09 53 17

This flowchart represents the second one:

Schermata 2021-10-16 alle 09 53 26
martasoricetti commented 2 years ago

This is the flowchart for the first algorithm

WhatsApp Image 2021-10-16 at 12 30 47

I tried to represent the second agorithm through a flowchart too, but I'm not sure at all about the result

WhatsApp Image 2021-10-17 at 15 22 06

MaddaGh commented 2 years ago

fibonacci1

This is only for the first algorithm since I didn't really understand how to represent second algorithm in a flowchart

AmeliaLamargese commented 2 years ago

ex 3 I was able to create the flowchart just for the first algorithm.

rahak commented 2 years ago

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 :

fibonacci_1

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 2 years ago

I tried to put the second algorithm in a flowchart but at the end I got in an infinite loop of 13s image

Then, when I saw the answers from my colleagues I realized I put an extra "if" that was making the loop infinite, so the end diagram is

image

olgagolgan commented 2 years ago

representation of the first description in natural language of the Fibonacci's algorithm

image

representation of the second description in natural language of the Fibonacci's algorithm

image

NoraPs commented 2 years ago

Representation of the first description in natural language of the Fibonacci's algorithm flow 1 drawio (2)

Representation of the second description (probably wrong)

flow 1-Page-2 drawio (1)

angstigone commented 2 years ago

first definition: exercise 31

second definition exercise32 :

giorgimariachiara commented 2 years ago

Flowchart 1 IMG_20211017_200317

giorgimariachiara commented 2 years ago

Flowchart 2

IMG_20211017_201237

elizastuglik commented 2 years ago

First Flowchart WhatsApp Image 2021-10-17 at 21 52 43 (1)

Second Flowchart WhatsApp Image 2021-10-17 at 21 58 36

chloeppd commented 2 years ago
  1. Screenshot 2021-10-17 at 10 39 11 PM
  2. IMG_20211019_232338

ManuSrivastava1 commented 2 years ago

The recursive style algorithm is on the right. Not 100% sure about it though.

recursive fib

sanyuezoe commented 2 years ago

exercise3

RebeccaJillianBeattie commented 2 years ago

Flow chart 1 (I realised it was necessary, I think, to split up the assignments of a and b, and c into two separate widgets)

IMG_20211018_180211.jpg

Flowchart 2

IMG_20211018_180247.jpg

CarmenSantaniello commented 2 years ago

First flowchart: 1

Second flowchart: 2

francescabudel commented 2 years ago

First flowchart (without recursion) Untitled Diagram drawio

Second flowchart (with recursion) con recursion

Marethyu6 commented 2 years ago

Made the second one after the suggestion given during last class

Algorithm_Ex3