Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an algorithm to draw Hasse diagram of the given relations in input.txt Your code should meet the following requirements, standards and accomplish the given

Write an algorithm to draw Hasse diagram of the given relations in input.txt

Your code should meet the following requirements, standards and accomplish the given tasks.

Read the relations from the text file input.txt

Determine each relation in input.txt whether it is reflexive, symmetric, anti-symmetric and transitive

In order to draw Hasse diagram, each relation must be POSET.

Hence, the relation obeys the following rules: Reflexivity Anti-symmetric Transitivity If the relation is not a POSET, your algorithm is responsible to CONVERT it to POSET.

If the relation is not reflexive, add new pairs to make the relation reflexive.

If the relation is symmetric, remove some pairs which make the relation symmetric. For instance, if the relation has (a, b) and (b, a), remove one of them randomly.

If the relation is not transitive, add new pairs which would make the relation transitive.

After the relation becomes POSET, your algorithm should obtain Hasse diagram of the relation and write the diagram with the following format.

An example of the output format is given in exampleoutput.txt. The file has the result of the first relation in input.txt.

In output.txt, each new Hasse diagram starts with n. The relation is (a, a), (a, b), (a, e), (b, b), (b, e), (c, c), (c, d), (d, d), (e, e)

The relation is already a POSET so we dont need to add or remove any pairs. After n, write the POSET in the next line as it is shown in exampleoutput.txt.

Since the relation is POSET, it becomes (a, b), (b, e), (c, d) after removing reflexive and transitive pairs.

The following lines give each pair of Hasse diagram. You can implement your algorithm in C programming

---------------------------------------------------------

"input.txt"

9 a,b,c,d,e a,a a,b a,e b,b b,e c,c c,d d,d e,e 8 a,b,c,d,e a,a a,b b,a b,b c,c c,d d,c d,d 5 a,b,c,d,e a,a b,b c,c d,d e,e 3 1,2,3,4 1,1 1,2 2,1 7 1,2,3,4 1,1 1,2 2,1 2,2 3,4 4,1 4,4 6 1,2,3,4 2,1 3,1 3,2 4,1 4,2 4,3 10 1,2,3,4 1,1 1,2 1,3 1,4 2,2 2,3 2,4 3,3 3,4 4,4 8 1,2,3,4 1,1 1,2 1,4 2,1 2,2 3,3 4,1 4,4

9 a,b,c,d,e a,a a,b a,e b,b b,e c,c c,d d,d e,e 8 a,b,c,d,e a,a a,b b,a b,b c,c c,d d,c d,d 5 a,b,c,d,e a,a b,b c,c d,d e,e 3 1,2,3,4 1,1 1,2 2,1 7 1,2,3,4 1,1 1,2 2,1 2,2 3,4 4,1 4,4 6 1,2,3,4 2,1 3,1 3,2 4,1 4,2 4,3 10 1,2,3,4 1,1 1,2 1,3 1,4 2,2 2,3 2,4 3,3 3,4 4,4 8 1,2,3,4 1,1 1,2 1,4 2,1 2,2 3,3 4,1 4,4

----------------------------------------------------------

exampleoutput.txt

n POSET: (a, a), (a, b), (a, e), (b, b), (b, e), (c, c), (c, d), (d, d), (e, e) a,b b,e c,d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions