What if you could instantly know if two people are connected without searching through endless lists?
Why Adjacency Matrix Representation in DSA C?
Imagine you want to keep track of friendships in a group of 100 people by writing down who is friends with whom on a big sheet of paper.
You try to list every pair manually to see if they are friends or not.
Writing down every pair manually is slow and confusing.
It is easy to miss some pairs or write wrong information.
Finding if two people are friends takes searching through a long list.
An adjacency matrix is like a neat table where rows and columns represent people.
Each cell tells if two people are friends with a simple yes or no.
This makes checking friendships quick and organized.
int isFriend(int personA, int personB, int friendships[][2], int size) { for (int i = 0; i < size; i++) { if ((friendships[i][0] == personA && friendships[i][1] == personB) || (friendships[i][0] == personB && friendships[i][1] == personA)) { return 1; } } return 0; }
int adjacencyMatrix[MAX][MAX];
int isFriend(int personA, int personB) {
return adjacencyMatrix[personA][personB];
}It enables instant answers to connection questions between any two points in a network.
Social media platforms use adjacency matrices to quickly find if two users are connected or to suggest new friends.
Manual listing of connections is slow and error-prone.
Adjacency matrix stores connections in a clear, fast-access table.
It makes checking relationships between nodes very quick.