Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lecture "Algorithms", exercise 2 #6

Open
essepuntato opened this issue Oct 15, 2021 · 26 comments
Open

Lecture "Algorithms", exercise 2 #6

essepuntato opened this issue Oct 15, 2021 · 26 comments
Labels

Comments

@essepuntato
Copy link
Contributor

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

@OrsolaMBorrini
Copy link

AlgorithmEx2
I don't know if this basic flowchart will be fine as an answer, I hope so!
Maybe a practical example could be the comparison between two strings. The decision widget can check if the two strings share the same alphanumeric characters in the same positions and if the two strings have the same length.
Another example could be the comparison between two files, if they are the same type or not (PDF, RTF, JPG...), but I don't think a shared type can exactly define two objects as "the same".

@ManueleVeggi
Copy link

I think the algorithm can be represented through this flowchart:

Schermata 2021-10-16 alle 09 49 33

@martasoricetti
Copy link

image

@AmeliaLamargese
Copy link

AmeliaLamargese commented Oct 16, 2021

ex 2

@rahak
Copy link

rahak commented Oct 16, 2021

yes:no

@AnastasiyaSopyryaeva
Copy link

task2

@Pablo751
Copy link

image

@olgagolgan
Copy link

image

@angstigone
Copy link

exercise 2

@victorchaix
Copy link

Answer Ex 2 Lec 3 CT

@giorgimariachiara
Copy link

IMG_20211017_194234

@ljutach
Copy link

ljutach commented Oct 17, 2021

Screenshot from 2021-10-17 19-57-59

@elizastuglik
Copy link

WhatsApp Image 2021-10-17 at 19 42 14

@chloeppd
Copy link

flowchart ex 2 (2)

@ManuSrivastava1
Copy link

string comparision

@lelax
Copy link

lelax commented Oct 18, 2021

FlowChart_2 drawio (1)

@sanyuezoe
Copy link

exercise2

@teragramgius
Copy link

teragramgius commented Oct 18, 2021

algorithm

SHOUT SHOOT

PREMISE

I wrote this in a couple of hours, not continuously but taking some breaks. I've been a little slow and I hope to be faster in the future.
I remember some math from high school, so I'm sure that there will be another mathematical form for what I've written in the algorithm.
I don't want to seem picky, I want to make the conversation start 😁 Let me know what you think

ASSUMPTION

According to the Oxford Dictionary, a letter is a written or printed sign representing a sound used in speech (https://www.oxfordlearnersdictionaries.com/definition/english/letter_1) .

So, for this example, we'll have in mind as input the words "SHOOT" and "SHOUT".

LET'S START

It is asked to input two words, and after that, to name them F(X) and G(Y) where X and Y indicate respectively the number of signs in the two words. If you want to take the example of SHOOT and SHOUT, we'll assume that SHOOT will be F(5) and SHOUT will be G(5).

After that, it is informed that, if the two numbers X and Y are the same, we have a chance that the algorithm will give as output "yes" (i.e. it would mean that the two words had the same sign number).

Next passage consists in naming every letter of the two words in numbers, respectively starting from 1 for A and so on.
It doesn't matter if the signs are in the uppercase or lowercase format.

Then it is asked to sum the first and the last number in G(X) and check if is the same as the sum of first and last number in F(Y).

If yes, it means that the two words in the input start and end with the same sign.
This is another step that give the algorithm a chance that it will give as output "yes".

A word has to have at least two signs. So in the next passage the flowline leads to a decision widget to see if the word constists in two signs of more.

If the signs are more, the flowline conducts the algorithm to a process widget, through which the algorithm will be able to know how many signs in the words are left, apart from the first and the last sign. (See the photo below)

So, if α= X-2=Y-2, where 2 is to exclude the first and last signs of the two words given as input,
then (X-α) = (Y-α) will indicate the remaining letters in the two words, both F(X) and G(Y).

At this point, what the algorithm have to check is whether the two words are the same or not.

So the algorithm will go through a process widget: every remaining sign in the two input words, transformed in number before, will get an indicative name: x₂ x₃ for signs in G(X) ... and y₂ y₃ for signs in F(Y)...
The numbers in subscript start from 2, since the first and last sign are excluded from this reasoning.

If the sum between the x₂ + x₃ ... is equal to the sum between y₂ + y₃ ... , then the agorithm will get as output "yes".
Otherwise, the two words will not be equal and the algorithm will return "no".

@CarmenSantaniello
Copy link

Diagramma senza titolo drawio

@ghasempouri1984
Copy link

print yes

@francescabudel
Copy link

g

@essepuntato
Copy link
Contributor Author

Hi all,

There are a few suggestions I list here that may be useful to improve your diagram and, in general, for even the future diagrams you will have to define:

  1. Read carefully the text of the algorithm to implement. If the text mentions "two objects", you cannot assume they are strings.
  2. Remember to use the correct widgets for introducing the correct instructions. For instance, when you need to return an output, you have to use an input/output widget always.
  3. The input is the first thing to do. An input/output widget must be used immediately after the initial terminal widget to declare which kind of input such an algorithm expects.
  4. You are not alone. Remember to ask some colleagues to check your algorithm by executing it on an input - this would allow you to see if what you wrote is comprehensible by another computer.

A note for @teragramgius: what happens if I run the algorithm specifying as input "shoot" and "thoos"?

@teragramgius
Copy link

All right, you got me🤣
Thank you🤝

@sarabecchi
Copy link

sarabecchi commented Oct 20, 2021

20211019_153759


def alg(obj_1, obj_2):
    if obj_1 == obj_2:
        return "yes"
    else:
        return "no"

print(alg("skyrim", "oblivion"))
print(alg("skyrim", "Skyrim"))
print(alg("skyrim", "skyrim"))

def test_alg(obj_1, obj_2, expected):
    result = alg(obj_1, obj_2)
    if result == expected:
        return True
    else:
        return False

print(test_alg("skyrim", "oblivion", "no"))
print(test_alg("skyrim", "Skyrim", "no"))
print(test_alg("skyrim", "skyrim", "yes"))


OUTPUT:

no
no
yes
True
True
True

@Marethyu6
Copy link
Contributor

Hope that's fine
Untitled Diagram drawio

@mirna-regolo
Copy link

exercise 2-flowchart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests