$29
Course Policy: Read all the instructions below carefully before you start working on the assignment, and before you make a submission.
It is not a group homework. Do not share your answers to anyone in any circumstance. Any cheating means at least -100 for both sides.
Do not take any information from Internet. No late homework will be accepted.
For any questions about the homework, send an email to gizemsungu@gtu.edu.tr
The homeworks (both latex and pdf les in a zip le) will be submitted into the course page of Moodle. The latex, pdf and zip les of the homeworks should be saved as "Name Surname StudentId".ftex, pdf,
zipg.
If the answers of the homeworks have only calculations without any formula or any explanation -when needed- will get zero.
Writing the homeworks on Latex is strongly suggested. However, hand-written paper is still accepted IFF hand writing of the student is clear and understandable to read, and the paper is well-organized. Otherwise, the assistant cannot grade the student’s homework.
Problem 1: Relations
(15 points)
Draw the Hasse diagram for the \greater than or equal to" relation on f0, 1, 2, 3, 4, 5g. Show each step to build the diagram. In order to draw the diagram, you can choose one of the following options:
You can use an online drawing tool such as https://app.diagrams.net/.
You can draw the diagram by hand, take a picture of it to put on Latex as a gure. Word O ce, Libre O ce are also options to use them as drawing tools.
(Solution)
1
{ Homework #2
Problem 2: Relations
2
(15 points)
Answer these questions for the poset (ff1g, f2g, f4g, f1, 2g, f1, 4g, f2, 4g, f3, 4g, f1, 3, 4g, f2, 3, 4gg, ).
(a) Find the maximal elements. (Solution)
(b) Find the minimal elements. (Solution)
(c) Is there a greatest element? (Solution)
(d) Find all upper bounds of ff2g, f4gg. (Solution)
(e) Find the least upper bound of ff2g, f4gg, if it exists. (Solution)
(f) Find all lower bounds of ff1, 3, 4g, f2, 3, 4gg. (Solution)
(h) Find the greatest lower bound of ff1, 3, 4g, f2, 3, 4gg, if it exists. (Solution)
{ Homework #2
Problem 3: Relations
3
(70 points)
Remember that a relation R on a set A can have the properties re exive, symmetric, anti-symmetric and transitive.
Re exive: R is re exive if (a, a) 2 R, 8 a 2 A.
Symmetric: R is symmetric if (b, a) 2 R whenever (a, b) 2 R, 8 a, b 2 A.
Anti-symmetric: R is antisymmetric if 8 a, b 2 A, (a, b) 2 R and (b, a) 2 R implies that a = b.
Transitive: R is transitive if 8 a, b, c 2 A, (a, b) 2 R and (b, c) 2 R implies that (a, c) 2 R.
For the details about the properties, please check the 4th lecture slide on Moodle.
As we solved the problem 3 in PS4 document - which is available on Moodle - in the problem session, we can determine any given relation if it is re exive, symmetric, anti-symmetric, and transitive.
Write an algorithm to determine if a given relation R is re exive, symmetric, anti-symmetric, and transitive.
Your code should meet the following requirements, standards and tasks.
Read the relations in the text le "input.txt".
Let R be a relation on a set A where 9a; b 2 A; (a; b) 2 R. Each relation R is represented with the lines in the le:
1. The rst line says how many relations in R.
2. The second line gives the elements of the set A.
3. The following lines give each relation in R.
After determining each relation in input.txt whether it is re exive, symmetric, anti-symmetric and tran-sitive with your algorithm, write its result to the le which is called "output.txt" with the following format.
output.txt:
1. Start a new line with "n" which indicates a new relation.
2. The set of R
3. Re exive: Yes or No, explain the reason if No (e.g. "(a, a) is not found").
4. Symmetric: Yes or No, explain the reason if No (e.g. "(b, a) is not found whereas (a, b) is found.")
5. Antisymmetric: Yes or No, explain the reason if No (e.g. "(b, a) and (a, b) are found.")
6. Transitive: Yes or No, explain the reason if No (e.g. "(a, c) is not found whereas (a, b) and (b, c) are found.")
An example of the output format is given in "exampleoutput.txt". The le has the result of the rst relation in "input.txt".
When explaining why a property does not exist in the relation, one reason is enough to explain if there are more. For example, in "exampleoutput.txt", the relation is not symmetric because (b, a) and (e, a) are not found. Detecting one of them is enough to explain the reason.
Bonus (20 points): If you can explain why a property exists in the relation, it brings you bonus of 20 points.
Your code is responsible to provide exception and error handling. The input le may be given with a wrong information, then your code must be prepared to detect them. For instance, "The element b of the relation (1, b) is not found in the set A = f1; 2; 3; 4g.".
You can implement your algorithm in Python, Java, C or C++.
Important: Put comments almost for each line of your code to describe what the line is going to do. You should put your source code le ( le name is problem1.f:c; :java; :py; :cppg) and output.txt into your
homework zip le (check Course Policy).