- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will explain the approaches to find the number of reflexive relations on a set. In this problem, we are given with number n, and on a set of n natural numbers, we must determine the number of reflexive relations.

**Reflexive Relation** − A relation in a set A is called reflexive if ( a, a ) belongs to R for every 'a' belongs to set A. For example −

Input : x = 1 Output : 1 Explanation : set = { 1 }, reflexive relations on A * A : { { 1 } } Input : x = 2 Output : 4 Explanation : set = { 1,2 }, reflexive relations on A * A : { ( 1, 1 ) , ( 2, 2 ) } { ( 1, 1 ), ( 2, 2 ), ( 1, 2 ) } { ( 1, 1 ), ( 2, 2 ), ( 1, 2 ), ( 2, 1 ) } { ( 1, 1 ), ( 2, 2 ), ( 2, 1 ) }

Hence, a relation is reflexive if: (a, a) ∈ R ∀ a ∈ A.

This number of reflexive relations on an element set can be solved by formula 2n2−n. This general formula is generated by calculating the number of reflexive relations of integers.

#include <iostream> using namespace std; int countReflexive(int n){ int ans = 1 << (n*n - n); return ans; } int main(){ int n ; cin >> n ; // taking input n from the user using std cin. int result = countReflexive(n); // calling function to calculate number of reflexive relations cout << "Number of reflexive relations on set: " << result ; // printing the answer return 0; }

Number of reflexive relations on set: 1

This program is simple to understand as we are just taking input from the user and putting it into the formula **2n2−n**, and we are using the left shift "<< "operator for calculating the formula, Time complexity of this code is O(1) which is getting slow as size of n increases.

In this article, we solve a problem to find the Number of Reflexive Relations on a Set. We discussed the simple approach to solve the given problem as a formula to calculate the number of reflexive relations is derived by mathematicians.

We also learned the C++ program for this problem by which we found the solution with a Time complexity of O(1). We can write the same program in other languages such as C, java, python, and other languages.

- Related Questions & Answers
- Relations of a Set
- Find the Number of Triangles Formed from a Set of Points on Three Lines using C++\n
- Find the number of Islands Using Disjoint Set in C++
- Find the Number of Pentagons and Hexagons on a Football using C++
- Representation of Relations using Graph
- Practice Set for Recurrence Relations
- Find the Number of Substrings of a String using C++
- Find the number of zeroes using C++
- Types of Relations
- Minimum number using set bits of a given number in C++
- Find the Number of Primes In A Subarray using C++
- Find the frequency of a digit in a number using C++.
- Find most significant set bit of a number in C++
- Find the Number of Stopping Stations using C++
- Find the number of stair steps using C++

Advertisements