Check Reflexive Relation on Set Last Updated : 20 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. To learn more about relations refer to the article on "Relation and their types".What is a Reflexive Relation?A relation R on a set A is called reflexive relation if (a, a) ∈ R ∀ a ∈ A, i.e. aRa for all a ∈ A, where R is a subset of (A x A), i.e. the cartesian product of set A with itself.This means if element "a" is present in set A, then a relation "a" to "a" (aRa) should be present in relation R. If any such aRa is not present in R then R is not a reflexive relation.A reflexive relation is denoted as:IA = {(a, a): a ∈ A}Example:Consider set A = {a, b} and R = {(a, a), (b, b)}.Here R is a reflexive relation as for both a and b, aRa and bRb are present in the set.Properties of a Reflexive RelationEmpty relation on a non-empty relation set is never reflexive.Relation defined on an empty set is always reflexive.Universal relation defined on any set is always reflexive.How to verify a Reflexive Relation?The process of identifying/verifying if any given relation is reflexive:Check for the existence of every aRa tuple in the relation for all a present in the set.If every tuple exists, only then the relation is reflexive. Otherwise, not reflexive.Follow the below illustration for a better understanding:Illustration:Consider set A = {a, b} and a relation R = {{a, a}, {a, b}}.For the element a in A: => The pair {a, a} is present in R. => Hence aRa is satisfied.For the element b in A: => The pair {b, b} is not present int R. => Hence bRb is not satisfied.As the condition for 'b' is not satisfied, the relation is not reflexive.Below is a code implementation of the approach. C++ // C++ code to check if a set is reflexive #include <bits/stdc++.h> using namespace std; class Relation { public: bool checkReflexive(set<int> A, set<pair<int, int> > R) { // Property 1 if (A.size() > 0 && R.size() == 0) { return false; } // Property 2 else if (A.size() == 0) { return true; } for (auto i = A.begin(); i != A.end(); i++) { // Making a tuple of same element auto temp = make_pair(*i, *i); if (R.find(temp) == R.end()) { // If aRa tuple not exists in relation R return false; } } // All aRa tuples exists in relation R return true; } }; // Driver code int main() { // Creating a set A set<int> A{ 1, 2, 3, 4 }; // Creating relation R set<pair<int, int> > R; // Inserting tuples in relation R R.insert(make_pair(1, 1)); R.insert(make_pair(1, 2)); R.insert(make_pair(2, 2)); R.insert(make_pair(2, 3)); R.insert(make_pair(3, 2)); R.insert(make_pair(3, 3)); Relation obj; // R in not reflexive as (4, 4) tuple is not present if (obj.checkReflexive(A, R)) { cout << "Reflexive Relation" << endl; } else { cout << "Not a Reflexive Relation" << endl; } return 0; } Java // Java code implementation for the above approach import java.io.*; import java.util.*; class pair { int first, second; pair(int first, int second) { this.first = first; this.second = second; } } class GFG { static class Relation { boolean checkReflexive(Set<Integer> A, Set<pair> R) { // Property 1 if (A.size() > 0 && R.size() == 0) { return false; } // Property 2 else if (A.size() == 0) { return true; } for (var i : A) { if (!R.contains(new pair(i, i))) { // If aRa tuple not exists in relation R return false; } } // All aRa tuples exists in relation R return true; } } public static void main(String[] args) { // Creating a set A Set<Integer> A = new HashSet<>(); A.add(1); A.add(2); A.add(3); A.add(4); // Creating relation R Set<pair> R = new HashSet<>(); // Inserting tuples in relation R R.add(new pair(1, 1)); R.add(new pair(1, 2)); R.add(new pair(2, 2)); R.add(new pair(2, 3)); R.add(new pair(3, 2)); R.add(new pair(3, 3)); Relation obj = new Relation(); // R in not reflexive as (4, 4) tuple is not present if (obj.checkReflexive(A, R)) { System.out.println("Reflexive Relation"); } else { System.out.println("Not a Reflexive Relation"); } } } // This code is contributed by lokeshmvs21. Python class Relation: def checkReflexive(self, A, R): # Property 1 if len(A) > 0 and len(R) == 0: return False # Property 2 elif len(A) == 0: return True for i in A: if (i, i) not in R: # If aRa tuple not exists in relation R return False # All aRa tuples exists in relation R return True # Driver code if __name__ == '__main__': # Creating a set A A = {1, 2, 3, 4} # Creating relation R R = {(1, 1), (1, 2), (2, 2), (2, 3), (3, 2), (3, 3)} obj = Relation() # R in not reflexive as (4, 4) tuple is not present if obj.checkReflexive(A, R): print("Reflexive Relation") else: print("Not a Reflexive Relation") C# // C# code implementation for the above approach using System; using System.Collections.Generic; class pair { public int first, second; public pair(int first, int second) { this.first = first; this.second = second; } } public class GFG { class Relation { public bool checkReflexive(HashSet<int> A, HashSet<pair> R) { // Property 1 if (A.Count > 0 && R.Count == 0) { return false; } // Property 2 else if (A.Count == 0) { return true; } foreach(var i in A) { if (!R.Contains(new pair(i, i))) { // If aRa tuple not exists in relation R return false; } } // All aRa tuples exists in relation R return true; } } static public void Main() { // Creating a set A HashSet<int> A = new HashSet<int>(); A.Add(1); A.Add(2); A.Add(3); A.Add(4); // Creating relation R HashSet<pair> R = new HashSet<pair>(); // Inserting tuples in relation R R.Add(new pair(1, 1)); R.Add(new pair(1, 2)); R.Add(new pair(2, 2)); R.Add(new pair(2, 3)); R.Add(new pair(3, 2)); R.Add(new pair(3, 3)); Relation obj = new Relation(); // R in not reflexive as (4, 4) tuple is not present if (obj.checkReflexive(A, R)) { Console.WriteLine("Reflexive Relation"); } else { Console.WriteLine("Not a Reflexive Relation"); } } } // This code is contributed by lokesh JavaScript // JS code to check if a set is reflexive function checkReflexive(A, R) { let cnt = 0; // Property 1 if (A.size > 0 && R.size == 0) { return false; } // Property 2 else if (A.size == 0) { return true; } A.forEach(i => { // Making a tuple of same element let temp = [i, i]; if (!R.has(temp)) { // If aRa tuple not exists in relation R cnt++; } }); // All aRa tuples exists in relation R if(cnt==0) return true; else return false; } // Driver code // Creating a set A let A = new Set([ 1, 2, 3, 4 ]); // Creating relation R let R = new Set(); // Inserting tuples in relation R R.add([1,1]); R.add([1,2]); R.add([2,2]); R.add([2,3]); R.add([3,2]); R.add([3,3]); R.add([3,3]); // R in not reflexive as (4, 4) tuple is not present if (checkReflexive(A, R)) { console.log("Reflexive Relation"); } else { console.log("Not a Reflexive Relation"); } // This code is contributed by akashish__ OutputNot a Reflexive RelationTime Complexity: O(N * log M) where N is the size of the set and M is the number of pairs in the relationAuxiliary Space: O(1) Comment More infoAdvertise with us Next Article Check Transitive Relation on a Set S Sharad_Jain Follow Improve Article Tags : DSA Similar Reads Discrete Mathematics Tutorial Discrete Mathematics is a branch of mathematics that is concerned with "discrete" mathematical structures instead of "continuous". Discrete mathematical structures include objects with distinct values like graphs, integers, logic-based statements, etc. In this tutorial, we have covered all the topic 3 min read Mathematical LogicPropositional LogicLogic is the basis of all mathematical reasoning and all automated reasoning. The rules of logic specify the meaning of mathematical statements. These rules help us understand and reason with statements such as -\exists~x~such~that~x~\neq~a^2~+~b^2,~where~\:x,~a,~b\in~ZWhich in Simple English means 10 min read Discrete Mathematics - Applications of Propositional LogicA proposition is an assertion, statement, or declarative sentence that can either be true or false but not both. For example, the sentence "Ram went to school." can either be true or false, but the case of both happening is not possible. So we can say, the sentence "Ram went to school." is a proposi 11 min read Propositional EquivalencesPropositional equivalences are fundamental concepts in logic that allow us to simplify and manipulate logical statements. Understanding these equivalences is crucial in computer science, engineering, and mathematics, as they are used to design circuits, optimize algorithms, and prove theorems. This 7 min read Predicates and QuantifiersPredicates and Quantifiers are fundamental concepts in mathematical logic, essential for expressing statements and reasoning about the properties of objects within a domain. These concepts are widely used in computer science, engineering, and mathematics to formulate precise and logical statements. 6 min read Mathematics | Some Theorems on Nested QuantifiersQuantifiers are expressions that indicate the scope of the term to which they are attached, they are predicates. A predicate is a property the subject of the statement can have. For example, in the statement "the sum of x and y is greater than 5", the predicate 'Q' is- sum is greater than 5, and the 6 min read Rules of InferenceRules of Inference: Rules of inference are logical tools used to derive conclusions from premises. They form the foundation of logical reasoning, allowing us to build arguments, prove theorems, and solve problems in mathematics, computer science, and philosophy. Understanding these rules is crucial 9 min read Mathematics | Introduction to ProofsMathematical proof is an argument we give logically to validate a mathematical statement. To validate a statement, we consider two things: A statement and Logical operators. A statement is either true or false but not both. Logical operators are AND, OR, NOT, If then, and If and only if. Coupled wit 7 min read Sets and RelationsSet TheorySet theory is a branch of mathematics that deals with collections of objects, called sets. A set is simply a collection of distinct elements, such as numbers, letters, or even everyday objects, that share a common property or rule.Example of SetsSome examples of sets include:A set of fruits: {apple, 3 min read Types Of SetsIn mathematics, a set is defined as a well-defined collection of distinct elements that share a common property. These elementsâ like numbers, letters, or even other sets are listed in curly brackets "{ }" and represented by capital letters. For example, a set can include days of the week. The diffe 13 min read Irreflexive Relation on a SetA relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. To learn more about relations refer to the article on "Relation and their types". What is Irreflexive Relation? A relation R on a set A is called irre 6 min read Check Reflexive Relation on SetA relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. To learn more about relations refer to the article on "Relation and their types".What is a Reflexive Relation?A relation R on a set A is called reflex 7 min read Check Transitive Relation on a SetA relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. To learn more about relations refer to the article on "Relation and their types".What is a Transitive Relation?A relation R on a set A is called trans 9 min read Set OperationsA set is simply a collection of distinct objects. These objects can be numbers, letters, or even peopleâanything! We denote a set using curly brackets.For example: A = {1, 2, 3}Set Operations can be defined as the operations performed on two or more sets to obtain a single set containing a combinati 10 min read Types of FunctionsFunctions are defined as the relations which give a particular output for a particular input value. A function has a domain and codomain (range). f(x) usually denotes a function where x is the input of the function. In general, a function is written as y = f(x).A function is a relation between two s 15 min read Mathematics | Sequence, Series and SummationsSequences, series, and summations are fundamental concepts of mathematical analysis and it has practical applications in science, engineering, and finance.Table of ContentWhat is Sequence?Theorems on SequencesProperties of SequencesWhat is Series?Properties of SeriesTheorems on SeriesSummation Defin 8 min read Representation of Relation in Graphs and MatricesUnderstanding how to represent relations in graphs and matrices is fundamental in engineering mathematics. These representations are not only crucial for theoretical understanding but also have significant practical applications in various fields of engineering, computer science, and data analysis. 8 min read Relations in MathematicsRelation in Mathematics is defined as the relationship between two sets. If we are given two sets set A and set B and set A has a relation with set B then each value of set A is related to a value of set B through some unique relation. Here, set A is called the domain of the relation, and set B is c 9 min read Closure of RelationsClosure of Relations: In mathematics, especially in the context of set theory and algebra, the closure of relations is a crucial concept. It involves extending a given relation to include additional elements based on specific properties, such as reflexivity, symmetry, and transitivity. Understanding 6 min read Mathematical InductionPigeonhole PrincipleThe Pigeonhole Principle is a fundamental concept in mathematics that is often used in problem-solving. It helps us understand situations where certain outcomes are inevitable, even if we donât know exactly how they will happen. The principle is named after the idea of putting pigeons into pigeonhol 9 min read Mathematics | Generalized PnC Set 1Prerequisite - PnC and Binomial Coefficients So far every problem discussed in previous articles has had sets of distinct elements, but sometimes problems may involve repeated use of elements. This article covers such problems, where elements of the set are indistinguishable (or identical or not dis 6 min read Discrete Maths | Generating Functions-Introduction and PrerequisitesDiscrete Maths | Generating Functions-Introduction and PrerequisitesPrerequisite - Combinatorics Basics, Generalized PnC Set 1, Set 2 Definition: Generating functions are used to represent sequences efficiently by coding the terms of a sequence as coefficients of powers of a variable (say) \big x in 5 min read Count Prime MultiplesGiven an array arr[] consisting of distinct prime numbers and an integer m, find how many numbers in the range from 1 to m (inclusive) are divisible by at least one of the prime numbers in the array.Examples:Input : arr[] = [2, 3, 5], m = 10Output : 8Explanation : From 1 to 10 there are 8 number whi 7 min read Boolean AlgebraProperties of Boolean AlgebraThe Boolean Algebra uses sets of rules for analyzing digital gates and circuits. In this article, we will be going through the Properties or Laws of the Boolean algebra. So first we will start our article by defining what are the properties of Boolean Algebra, and then we will go through what are Bo 7 min read Number of Boolean functionsA Boolean function is a mathematical function that takes one or more Boolean variables (each representing a binary value: true or false, 1 or 0) as input and produces a Boolean output (either true or false). Boolean functions are fundamental in fields like computer science, logic, and digital circui 5 min read Minimization of Boolean FunctionsBoolean functions are used to represent logical expressions in terms of sum of minterms or product of maxterms. Number of these literals (minterms or maxterms) increases as the complexity of the digital circuit increases. This can lead to large and inefficient circuits. By minimizing Boolean functio 4 min read Linear ProgrammingLinear programming is a mathematical concept that is used to find the optimal solution of a linear function. This method uses simple assumptions for optimizing the given function. Linear Programming has a huge real-world application, and it is used to solve various types of problems.The term "linear 15+ min read Ordered Sets & LatticesElements of POSET | Maximal Element, Minimal Element , Lower and Upper Bounds Partially Ordered Set (POSET) is a fundamental concept in mathematics and computer science, providing a structured way to analyze and compare elements within a set. In a POSET, not every pair of elements needs to be comparable, making it a versatile tool for representing hierarchical relationships a 10 min read Partial Order Relation on a SetA relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. What is a Partial Order Relation? A relation R on a set A is called a partial order relation if it is Reflexive Relation: (a, a) â R â a â A, i.e. aRa 15 min read Axiomatic Approach to ProbabilityHearing the word "probability" brings up ideas related to uncertainty or randomness. Although the concept of probability can be hard to describe formally, it helps us analyze how likely it is that a certain event will happen. This analysis helps us understand and describe many phenomena we see in re 10 min read Properties of ProbabilityProbabilityProbability is the branch of mathematics that is concerned with the chances of occurrence of events and possibilities. Further, it gives a method of measuring the probability of uncertainty and predicting events in the future by using the available information.Probability is a measure of 14 min read Probability TheoryUniform Distribution in Data ScienceUniform Distribution also known as the Rectangular Distribution is a type of Continuous Probability Distribution where all outcomes in a given interval are equally likely. Unlike Normal Distribution which have varying probabilities across their range, Uniform Distribution has a constant probability 5 min read Exponential DistributionThe Exponential Distribution is one of the most commonly used probability distributions in statistics and data science. It is widely used to model the time or space between events in a Poisson process. In simple terms, it describes how long you have to wait before something happens, like a bus arriv 3 min read Normal Distribution in Data ScienceNormal Distribution also known as the Gaussian Distribution or Bell-shaped Distribution is one of the widely used probability distributions in statistics. It plays an important role in probability theory and statistics basically in the Central Limit Theorem (CLT). It is characterized by its bell-sha 6 min read Poisson Distribution in Data SciencePoisson Distribution is a discrete probability distribution that models the number of events occurring in a fixed interval of time or space given a constant average rate of occurrence. Unlike the Binomial Distribution which is used when the number of trials is fixed, the Poisson Distribution is used 7 min read Graph TheoryGraph and its representationsA Graph is a non-linear data structure consisting of vertices and edges. The vertices are sometimes also referred to as nodes and the edges are lines or arcs that connect any two nodes in the graph. More formally a Graph is composed of a set of vertices( V ) and a set of edges( E ). The graph is den 12 min read Mathematics | Graph Theory Basics - Set 1A Graph is just a way to show connections between things. It is set of edges and vertices where each edge is associated with unordered pair of vertices. Graph is a data structure that is defined by two components :Node or Vertex: It is a point or joint between two lines like people, cities, or websi 5 min read Types of Graphs with ExamplesA graph is a mathematical structure that represents relationships between objects by connecting a set of points. It is used to establish a pairwise relationship between elements in a given set. graphs are widely used in discrete mathematics, computer science, and network theory to represent relation 9 min read Walks, Trails, Paths, Cycles and Circuits in GraphWalks, trails, paths, cycles, and circuits in a graph are sequences of vertices and edges with different properties. Some allow repetition of vertices and edges, while others do not. In this article, we will explore these concepts with examples.What is Walk?A walk in a graph is a sequence of vertice 6 min read Dijkstra's Algorithm to find Shortest Paths from a Source to allGiven a weighted undirected graph represented as an edge list and a source vertex src, find the shortest path distances from the source vertex to all other vertices in the graph. The graph contains V vertices, numbered from 0 to V - 1.Note: The given graph does not contain any negative edge. Example 12 min read Primâs Algorithm for Minimum Spanning Tree (MST)Primâs algorithm is a Greedy algorithm like Kruskal's algorithm. This algorithm always starts with a single node and moves through several adjacent nodes, in order to explore all of the connected edges along the way.The algorithm starts with an empty spanning tree. The idea is to maintain two sets o 15+ min read Kruskalâs Minimum Spanning Tree (MST) AlgorithmA minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected, and undirected graph is a spanning tree (no cycles and connects all vertices) that has minimum weight. The weight of a spanning tree is the sum of all edges in the tree. In Kruskal's algorithm, we sort all edges 9 min read Check whether a given graph is Bipartite or notGiven a graph with V vertices numbered from 0 to V-1 and a list of edges, determine whether the graph is bipartite or not.Note: A bipartite graph is a type of graph where the set of vertices can be divided into two disjoint sets, say U and V, such that every edge connects a vertex in U to a vertex i 8 min read Eulerian path and circuit for undirected graphGiven an undirected connected graph with v nodes, and e edges, with adjacency list adj. We need to write a function that returns 2 if the graph contains an eulerian circuit or cycle, else if the graph contains an eulerian path, returns 1, otherwise, returns 0.A graph is said to be Eulerian if it con 9 min read Special GraphIntroduction to Graph ColoringGraph coloring refers to the problem of coloring vertices of a graph in such a way that no two adjacent vertices have the same color. This is also called the vertex coloring problem. If coloring is done using at most m colors, it is called m-coloring. Chromatic Number:The minimum number of colors ne 11 min read Edge Coloring of a GraphIn graph theory, edge coloring of a graph is an assignment of "colors" to the edges of the graph so that no two adjacent edges have the same color with an optimal number of colors. Two edges are said to be adjacent if they are connected to the same vertex. There is no known polynomial time algorithm 9 min read Check if a graph is Strongly, Unilaterally or Weakly connectedGiven an unweighted directed graph G as a path matrix, the task is to find out if the graph is Strongly Connected or Unilaterally Connected or Weakly Connected. Strongly Connected: A graph is said to be strongly connected if every pair of vertices(u, v) in the graph contains a path between each othe 12 min read Biconnected ComponentsA biconnected component is a maximal biconnected subgraph. Biconnected Graph is already discussed here. In this article, we will see how to find biconnected component in a graph using algorithm by John Hopcroft and Robert Tarjan. In above graph, following are the biconnected components: 4--2 3--4 3- 15+ min read Strongly Connected ComponentsStrongly Connected Components (SCCs) are a fundamental concept in graph theory and algorithms. In a directed graph, a Strongly Connected Component is a subset of vertices where every vertex in the subset is reachable from every other vertex in the same subset by traversing the directed edges. Findin 15+ min read Group TheoryMathematics | Graph Theory Basics - Set 1A Graph is just a way to show connections between things. It is set of edges and vertices where each edge is associated with unordered pair of vertices. Graph is a data structure that is defined by two components :Node or Vertex: It is a point or joint between two lines like people, cities, or websi 5 min read Homomorphism & Isomorphism of GroupWe can say that  "o" is the binary operation on set G if: G is a non-empty set & G * G = { (a,b) : a , bâ G } and o : G * G --> G. Here, aob denotes the image of ordered pair (a,b) under the function/operation o.Example - "+" is called a binary operation on G (any non-empty set ) if & onl 7 min read Group Isomorphisms and AutomorphismsIn the study of algebraic structures, group isomorphisms and automorphisms play a fundamental role. By defining internal symmetries inside a group (automorphisms) and when two groups have the same structure (isomorphisms), these ideas aid in our understanding of the structure and symmetry of groups. 7 min read Group in Maths: Group TheoryGroup theory is one of the most important branches of abstract algebra which is concerned with the concept of the group. A group consists of a set equipped with a binary operation that satisfies four key properties: specifically, it includes property of closure, associativity, the existence of an id 13 min read Like