Program To Verify Equivalence Relation On A Tree Structure
Program To Verify Equivalence Relation On A Tree Structure
by
NAME SANJAY KR CHAITANYA KUMAR B
USN NO. 01JST17CS139 01JST17CS037
ROLL NO. 38 07
INTRODUCTION
DOMAIN AND RANGE
If there are two sets A and B, and relation R have order pair (x, y), then –
The domain of R, Dom(R), is the set
{x|(x,y)∈R for some y in B} {x|(x,y)∈R for some y in B }
The range of R, Ran(R), is the set {y|(x,y)∈R for some x in A }
REFLEXIVE
A relation is reflexive if, we observe that for all values a: aRa
In other words, all values are related to themselves. The relation of equality, "="
is reflexive. Observe that for, say, all numbers a (the domain is R): a = a so "="
is reflexive. In a reflexive relation, we have arrows for all values in the domain
pointing back to themselves:
SYMMETRIC
A relation is symmetric if, we observe that for all values of a and b:
a R b implies b R a.
The relation of equality again is symmetric. If x=y, we can also write
that y=x also. In a symmetric relation, for each arrow we have also an opposite
arrow, i.e. there is either no arrow between x and y, or an arrow points
from x to y and an arrow back from y to x:
TRANSITIVE
A relation is transitive if for all values a, b, c: a R b and b R c implies a R c
The relation greater-than ">" is transitive. If x > y, and y > z, then it is true
that x > z. This becomes clearer when we write down what is happening into
words. x is greater than y and y is greater than z. So x is greater than
both y and z. The relation is-not-equal "≠" is not transitive.
If x ≠ y and y ≠ z then we might have x = z or x ≠ z.In the arrow diagram, every
arrow between two values a and b, and b and c, has an arrow going straight
from a to c.
EQUIVALENCE RELATIONS
We have seen that certain common relations such as "=", and congruence
(which we will deal with in the next section) obey some of these rules above.
The relations we will deal with are very important in discrete mathematics, and
are known as equivalence relations. They essentially assert some kind of
equality notion, or equivalence, hence the name.
ALGORITHM
C PROGRAM TO FIND EQUIVALENCE RELATION ON A TREE
C STRUCTURE
START PROGRAM
CREATE STRUCTRE TREE
DECLARE X,Y AND LINK POINTER
CREATE POINTER TO STRUCTER TREE
INITIALIZE AND ALLOCATE MEMORY TO TREE
C DECLARE FUNCTIONS INSERT DISPLAY SYMMETRIC
TRANSITIVE FINID
C IN THE MAIN FUNCTION
START MAIN
DECLARE N AND DECLARE POINTER TO TREE
READ NUMBER OF ELEMENTS AND THE ELEMENTS
CALL INSERT
PRINT ELEMENTS
CALL DISPLAY
START IF
IF REFLEXIVE
PRINT REFLEXIVE
ELSE
PRINT NOT REFLEXIVE
END IF
START IF
IF SYMMETRIC
PRINT SYMMETRIC
ELSE
PRINT NOT SYMMETRIC
END IF
START IF
IF TRANSITIVE
PRINT TRANSITIVE
ELSE
PRINT NOT TRANSITIVE
END IF
START IF
IF REFLEXIVE AND SYMMETRIC AND TRANSITIVE
PRINT EQUIVALENCE RELATION
ELSE
PRINT NOT EQUIVALENCE RELATION
END IF
END MAIN FUNCTION
C
START INSERT
READ ORDERED PAIRS IN RELATION AND COUNT
END INSERT
C
START DISPLAY
CTEATE TREE NODE
PRINT ORDERED PAIRS
END DISPLAY
C
START SYMMETRIC
CREATE TREE NODE
START WHILE
ASSIGN X,Y FORM TREE DATA
START IF
CALL FIND IS NULL
RETURN
END IF
RETURN 1
END WHILE
END SYMMETRIC
C
START FIND
CREATE TREE NODE
START WHILE FOR ALL NODES IN TREE
START IF
X IS EQUAL TO DATA Y AND Y IS EQUAL NODE DATA X
RETURN 1
END IF
END WHILE
RETURN 0
END FIND
C
START TRANSITIVE
CREATE TWO TREE NODES
START WHILE
DECLARE X,Y
START WHILE FOR ALL NODES
START IF
NODE DATA Y IS EQUAL TO NODE DATA X
CALL FIND
END IF
END WHILE
RETURN 1
END WHILE
END TRANSITIVE
C
END PROGRAM
PROGRAM
#include<stdio.h>
#include <stdlib.h>
struct tree
{
int x,y;
struct tree *link;
};
Tree getnode()
{
Tree T;
T = (Tree)malloc(sizeof(struct tree));
T->link = NULL;
return T;
}
int insert(Tree);
void display(Tree);
int symmetric(Tree);
int transitive(Tree);
int find(Tree,int,int);
int main()
{
int n,i;
Tree F;
F=getnode();
printf("Enter the no of elements in the set
A\n");
scanf("%d",&n);
int set[n];
printf("Enter the elements in the set A\n");
for(i = 0; i < n; i++)
scanf("%d",&set[i]);
int cnt = insert(F);
printf("The elements in the set are ");
for(i=0;i<n;i++)
printf("%d ",set[i]);
printf("\n");
display(F);
int reflexive = 0;
if(cnt == n)
reflexive = 1;
if(reflexive)
printf("R is Reflexive\n");
else
printf("R is not reflexive\n");
int k;
k = symmetric(F);
if(k==1)
printf("R is symmetric\n");
else
printf("R is not symmetric\n");
int l = transitive(F);
if(l == 1)
printf("R is transitive\n");
else
printf("R is not transitive\n");
if(reflexive==1 && k==1 && l==1)
printf("R is equevalence relation\n");
else
printf("R is not equevalence relation\n");
return 0;
}
int insert(Tree F)
{
int x, y,c = 0;
printf("Enter the order pair to form the
relation\n");
while(1)
{
scanf("%d%d",&x,&y);
if(x == -1 || y == -1)
break;
if(x == y)
c++;
Tree nn = getnode();
nn->x = x;
nn->y = y;
nn->link = F->link;
F->link = nn;
}
return c;
}
void display(Tree F)
{
Tree T;
printf("The order pair are ");
T=F->link;
while(T!=NULL)
{
printf("(%d,%d),",T->x,T->y);
T = T->link;
}
printf("\n");
}
int symmetric(Tree F)
{
Tree T;
int x,y;
T=F->link;
while(T!=NULL)
{
x=T->x;
y=T->y;
if(!find(F,y,x))
return 0;
T=T->link;
}
return 1;
}
int transitive(Tree T)
{
Tree Q,F;
int x,y;
F = T->link;
while(F!=NULL)
{
x=F->x;
y=F->y;
Q = T->link;
while(Q != NULL)
{
if(Q->x == y)
if(!find(T,x,Q->y))
return 0;
Q = Q->link;
}
F = F->link;
}
return 1;
}
OUTPUT
Enter the no of elements in the set A
3
11
22
33
12
23
31
13
32
21
-1 0
R is Reflexive
R is symmetric
R is transitive
R is equevalence relation
APPLLICATION
Relations are subsets of two given sets. For example, R of A and B is shown
through AXB. This example is what’s known as a full relation. Now, about the
applications of set relations in specific or even Set Theory in general, there are
several:
Examples
1. Fractions are notations of the form a/b, where a and b are integers, and b is
not zero. Rational numbers are the fraction which are the equivalence
classes of fractions under the relation that says a/b ≡ c/d if ad = bc , because
for example 3/8 and 8/16 are the same rational number. But having
identified the process, we can now apply it to all sorts of things more
complicated than the integers.
2. We can relate the complex numbers to polynomials by defining each
complex number as a part of a partition induced on the set of polynomials
by a certain equivalence relation. By using different equivalence relations
we can define different systems analogous to the complex numbers and use
them to study properties of polynomials.
3. Mathematics has a structure called a group, which is a model of a way in
which a thing can have symmetry. There is an important “quotient”
operation on a group which arises when you consider certain symmetries to
be “equivalent”; the quotient is a group that describes the symmetries of the
resulting equivalence classes.
4. This is a very specific example: Consider some geometric object which has
an even number of symmetries. Then the object must have at least one
symmetry which is an “involution”:. Objects without involutions must have
an odd number of symmetries! (An example is a table-saw blade with 37
teeth.)
5. An important technique in physics is to analyse the symmetries of the
universe itself. For example, the laws of conservation of momentum and
energy are consequences of certain symmetries of space-time. The abstract
structure of spaces with these symmetries is often best understood as a
particular quotient group.
6. This “quotient” idea applies in other situations too. Many kinds of
mathematical structures are best understood as quotients, in this sense. For
example, in topology we often view a circle as being a quotient of a line
segment, under the equivalence relation that says that the two endpoints are
equivalent. When we want to deal with a Möbius strip, we often formulate it
as a certain quotient of a rectangle, where the equivalence relation makes
certain points on the edge of the rectangle equivalent. Many related objects,
much weirder than the Möbius strip, can be dealt with similarly.
CONCLUSION
We don't study the identification between partitions and equivalence relations
just because it is cool. It is also useful in understanding other things. Partitions
and equivalence relations pop up everywhere. Sometimes the partition is
obvious, but the equivalence relation is easier to understand; then it is helpful to
reinterpret the partition as an equivalence relation. Sometimes it is useful to go
in the other direction instead.
REFERENCES
Ralph.P.Grimaldi, B.V.Ramana, “Discrete and Combinatorial
Mathematics”, 5th Edition, Pearson Education -2009.
Kenneth. H.Rosen, “Discrete Mathematical Structures Theory and
Application”, V Edition, PHI/Pearson, Education, 2004.
Kolman, Busby and Ross, “Discrete Mathematical Structures”,
Fourth Edition, Prentice –Hall of India Pvt Ltd-2009.
https://math.stackexchange.com/questions/2525064/why-do-we-
care-about-equivalence-relations