comp-think/2018-2019

Lecture "Algorithms", exercise 2

Opened this issue · 15 comments

Write the flowchart of an algorithm that takes in input two objects and returns “yes” whether the two objects are the same, otherwise it returns “no”.

diagram
I also thought- not sure about that, though-: if the two objects are numbers:

diagramuu

msdiagram

same

untitled diagram

untitled diagram

algorithms_exercise_2

Hi all,

Thanks for your answers. Please remember that, even if the flowcharts are an informal way to describe an algorithm, if the computational problem in input says that one should return "yes" or "no", then that is what it is expected. In particular, returning numbers, for instance, is not the right way of implementing the algorithm – even if it is pretty clear to me what the numbers actually stand for.

Another issue that I saw is that some of you have used explicitly names of different objects in body of the algorithm (e.g. marker vs. pen). This should be avoided in the definition of the algorithm, since it seems that the only possibility that such algorithm has is to take in input a marker and a pen, while it is supposed to work with any input object – e.g. what if I want to run it using two pens, or an apple and an orange?

Finally, if you initialise something (e.g. "initialise result = 0"), then one should use it somehow (e.g. by returning the result value). See the example in the lecture notes for clarification on this passage.