Open any Grade 10 student's phone in India and you will almost certainly find a WhatsApp group buzzing with classmates, a set of Instagram accounts followed and followed-back, and a mental map of who is friends with whom, who had a falling-out last month, and who introduced whom to their now-best-friend. That mental map is data. It has a precise mathematical shape — one that can be measured, calculated, and even predicted. The branch of computer science that studies this shape is called social network analysis, and it rests on one of the oldest and most useful ideas in computer science: the graph.
Consider a small friend circle from a Grade 10 class: Aditi, Rohan, Meera, Karan, Priya, and Sanjay. Aditi, Rohan, and Meera hang out constantly and are all friends with each other. Karan is friends with Aditi and Meera too, but he is also the one who introduced his friend Priya to the group — though Priya never quite clicked with Aditi, Rohan, or Meera. Priya, in turn, is close with Sanjay, who does not know anyone else in the group. Before we can calculate anything about this circle — who is the most "central" person, how many "hops" separate the most distant pair, which single friendship holds two smaller clusters together — we need a precise way to represent "who is connected to whom." That precise representation is a graph.
What Exactly Is a Graph?
A graph is a mathematical structure built from two simple ingredients: nodes (also called vertices), which represent the things being connected, and edges, which represent the connections themselves. In our friend circle, each of the six students is a node, and each friendship is an edge joining two nodes.
Graphs come in a few important flavors, and choosing the right one matters:
- In an undirected graph, an edge has no direction — if Aditi is connected to Rohan, Rohan is automatically connected to Aditi. Mutual friendships work this way.
- In a directed graph, an edge points one way. Instagram "follows" are directed: you can follow a celebrity who has never heard of you, so an edge from Sanjay to a cricketer he follows does not imply an edge back.
- In a weighted graph, edges carry a number describing the strength of a connection — perhaps how many messages two people exchanged this week. An unweighted graph only records whether a connection exists, with no notion of "how much."
Our class friend circle is a simple, undirected, unweighted graph: two people are either friends or they are not, and friendship runs both ways.
To do anything useful with a graph on a computer, we need to store it in a data structure. Two representations dominate. An adjacency list stores, for each node, the list of nodes it is directly connected to — compact and efficient when most possible connections do not exist, which is exactly the case in real social networks, where any one person is friends with a tiny fraction of everyone else. An adjacency matrix stores an n × n grid, where a 1 in row i, column j means node i is connected to node j, and a 0 means it is not — simple to reason about, but wasteful when connections are sparse, which is almost always true for social networks. Because our example is sparse, we will use an adjacency list, both on paper and in code.
Building Our Network in Code
Here is the adjacency list for our six-student circle, translated directly into a Python dictionary, where each key is a person and each value is the list of their friends:
friend_circle = {
"Aditi": ["Rohan", "Meera", "Karan"],
"Rohan": ["Aditi", "Meera"],
"Meera": ["Aditi", "Rohan", "Karan"],
"Karan": ["Aditi", "Meera", "Priya"],
"Priya": ["Karan", "Sanjay"],
"Sanjay": ["Priya"],
}
Notice that the graph is stored twice over, in a sense: Rohan appears in Aditi's list, and Aditi appears in Rohan's list. This redundancy is intentional and correct — it is exactly what makes the graph undirected. If you ever find an entry that is not mirrored (say, Karan lists Priya as a friend, but Priya's list does not include Karan), that is a bug, not a feature, in an undirected friendship graph.
Degree Centrality: Who Is "Popular"?
The simplest measure in social network analysis is degree — the number of direct connections a node has. In a friendship graph, degree is simply the friend count. The measure built from it, degree centrality, ranks nodes by how many direct connections they hold. Computing degree for every person is one short loop:
for person, friends in friend_circle.items():
print(f"{person}: degree {len(friends)}")
Running this over our circle gives:
Aditi: degree 3
Rohan: degree 2
Meera: degree 3
Karan: degree 3
Priya: degree 2
Sanjay: degree 1
Aditi, Meera, and Karan are tied for the highest degree centrality in this circle, each with three direct friendships. Sanjay sits at the other end, with a single connection, to Priya. By this measure alone, Aditi, Meera, and Karan look equally "important" in the network. As we will see later in this chapter, that is not the whole story.
The Friendship Paradox
Here is a genuinely strange, well-documented fact about almost every social network, real or constructed: on average, your friends have more friends than you do. This is not a quirk of unlucky individuals — sociologist Scott Feld proved it mathematically in 1991 and named it the friendship paradox. Let's verify it ourselves, using our six-student circle, one careful step at a time.
First, recall each person's degree: Aditi 3, Rohan 2, Meera 3, Karan 3, Priya 2, Sanjay 1. Now, for each person, look at their friends' degrees and average them:
- Aditi's friends are Rohan (2), Meera (3), and Karan (3). Average: (2 + 3 + 3) ÷ 3 = 2.67.
- Rohan's friends are Aditi (3) and Meera (3). Average: (3 + 3) ÷ 2 = 3.00.
- Meera's friends are Aditi (3), Rohan (2), and Karan (3). Average: (3 + 2 + 3) ÷ 3 = 2.67.
- Karan's friends are Aditi (3), Meera (3), and Priya (2). Average: (3 + 3 + 2) ÷ 3 = 2.67.
- Priya's friends are Karan (3) and Sanjay (1). Average: (3 + 1) ÷ 2 = 2.00.
- Sanjay's only friend is Priya (2). Average: 2.00.
Now compare two different averages across the whole circle. The plain network average degree is the total degree divided by the number of people: (3 + 2 + 3 + 3 + 2 + 1) ÷ 6 = 14 ÷ 6 ≈ 2.33. For the second average, add up the six "friends' average degree" figures above before rounding: 8/3 + 3 + 8/3 + 8/3 + 2 + 2 = 8 + 7 = 15. Divide by the 6 people: 15 ÷ 6 = 2.50 exactly.
2.50 is greater than 2.33. Even in this tiny circle of six people, the paradox holds exactly as Feld's mathematics predicts: friends, on average, have more friends than the average person does. Here is the same calculation in code, to confirm it:
degree = {p: len(f) for p, f in friend_circle.items()}
friend_averages = []
for friends in friend_circle.values():
total = sum(degree[f] for f in friends)
friend_averages.append(total / len(friends))
network_avg = sum(degree.values()) / len(degree)
friend_avg = sum(friend_averages) / len(friend_averages)
print(f"Average degree in the network: {network_avg:.2f}")
print(f"Average degree of a friend: {friend_avg:.2f}")
This prints exactly 2.33 and 2.50, confirming the hand calculation. The reason is not mysterious once you see it structurally. A highly-connected person — a hub, like Aditi, Meera, or Karan — shows up in many other people's friend lists, once for every person who lists them as a friend. A person with few connections, like Sanjay, barely gets counted at all. When you average "friends' friend-counts," the popular hubs get counted repeatedly, quietly pulling the average upward. This is also why, if you compare your own follower count to the follower counts of people you follow, you will often feel like everyone else is more popular than you — it is a structural property of any network with hubs, not a reflection of your own social standing.
Shortest Paths and Six Degrees of Separation
Degree centrality only looks one step away. A richer question is: what is the shortest chain of friendships connecting any two people in the network? This is exactly the kind of question psychologist Stanley Milgram tried to answer experimentally in 1967. He gave people in Nebraska a document addressed to a stockbroker in Boston and asked them to forward it — not directly, since they did not know him, but to a personal acquaintance they thought might be socially "closer" to the target, who would repeat the process. Among the chains that reached their destination, the median length was around five to six intermediaries, the origin of the popular idea that any two people are connected by roughly "six degrees of separation."
Modern data confirms Milgram's rough estimate at a scale he could never have tested by hand. In 2011, Facebook's data scientists analyzed the friendship graph of hundreds of millions of active users and calculated the shortest-path distance between random pairs of people. The average came out to about 4.7 — meaning that on a network vastly larger and denser than Milgram's 1960s America, two random users were typically separated by fewer than five friendships. The finding was widely reported as "four degrees of separation."
In graph terms, "shortest chain of friendships" is a shortest path problem, and the standard algorithm for solving it on an unweighted graph — where every edge counts as one "hop," with no edge being "closer" than another — is breadth-first search, or BFS. BFS explores a graph in expanding rings: first every node one hop from the start, then every new node two hops away, and so on, guaranteeing that the first time BFS reaches a node, it has found the shortest possible path to it. Let's trace BFS ourselves, finding every person's distance from Sanjay, the least-connected member of our circle, using Python's deque as a queue:
from collections import deque
def hops_from(graph, start):
distance = {start: 0}
queue = deque([start])
while queue:
current = queue.popleft()
for neighbor in graph[current]:
if neighbor not in distance:
distance[neighbor] = distance[current] + 1
queue.append(neighbor)
return distance
print(hops_from(friend_circle, "Sanjay"))
Trace this by hand, one queue operation at a time:
- Start:
distance = {Sanjay: 0},queue = [Sanjay]. - Pop Sanjay. Its only neighbor, Priya, is unvisited, so
distance[Priya] = 1. Queue:[Priya]. - Pop Priya. Its neighbors are Karan and Sanjay. Sanjay is already visited; Karan is not, so
distance[Karan] = 2. Queue:[Karan]. - Pop Karan. Its neighbors are Aditi, Meera, and Priya. Priya is visited; Aditi and Meera are not, so
distance[Aditi] = 3anddistance[Meera] = 3. Queue:[Aditi, Meera]. - Pop Aditi. Its neighbors are Rohan, Meera, and Karan. Meera and Karan are visited; Rohan is not, so
distance[Rohan] = 4. Queue:[Meera, Rohan]. - Pop Meera. All three of its neighbors — Aditi, Rohan, Karan — are already in the distance dictionary, so nothing changes. Queue:
[Rohan]. - Pop Rohan. Both its neighbors, Aditi and Meera, are already visited. The queue is now empty, and the search ends.
The final result: {'Sanjay': 0, 'Priya': 1, 'Karan': 2, 'Aditi': 3, 'Meera': 3, 'Rohan': 4}. Even Rohan, the person structurally furthest from Sanjay in this circle, is only four handshakes away — and this is a circle of just six people. Scale this pattern up to a real network of hundreds of millions of people, layered with overlapping friend circles, workplaces, schools, and family ties, and it stops being surprising that researchers found an average distance of under five. Sparse local connections, it turns out, still add up to a very small world.
Bridges and Brokers: Betweenness Centrality
Recall that Aditi, Meera, and Karan were tied on degree centrality, each with three friends. But not all high-degree nodes play the same structural role. Look again at the shape of the circle: Aditi, Rohan, and Meera form a tightly-linked trio, Priya and Sanjay form a small pair off to the side, and Karan is the single hinge joining the two groups.
Test this by imagining Karan leaves the group. Priya's only remaining connection is Sanjay, and Sanjay's only connection was Priya. With Karan gone, the pair Priya–Sanjay is completely cut off from Aditi, Rohan, and Meera — no path connects them anymore. Now imagine instead that Aditi leaves. Rohan is still connected to Meera directly. Meera is still connected to Karan. Karan is still connected to Priya, and Priya is still connected to Sanjay. The whole remaining circle stays in one connected piece, just via a longer path.
Aditi and Karan have identical degree — three each — yet losing Karan fractures the network, while losing Aditi does not. Karan is what graph analysis calls a bridge, or in social terms, a broker: a node whose removal disconnects the graph, sitting at a structural chokepoint between groups that would otherwise have no path between them. The formal measure of this role is betweenness centrality, which counts how often a node lies on the shortest path between two other nodes. Check every shortest path between someone in the trio (Aditi, Rohan, Meera) and someone in the pair (Priya, Sanjay), and you will find Karan sitting on every single one of them — giving Karan a high betweenness score despite an entirely ordinary degree.
This distinction matters far beyond friend circles. A junior employee who is the only person talking regularly to both the engineering team and the sales team, a single railway junction connecting two otherwise separate lines, a lone group admin bridging two unrelated hostel wings — all of these are Karans. They may not have the most connections, but removing them does the most damage to how information, goods, or people actually flow.
How Tight-Knit Is Your Circle? Clustering Coefficient
One more question worth asking about any node: how tightly-knit is its immediate circle? If two of your friends are also friends with each other, that forms a triangle, a small unit of group cohesion. The clustering coefficient of a node measures the fraction of possible triangles among its friends that actually exist.
Take Aditi, whose three friends are Rohan, Meera, and Karan. There are three possible friendships among this trio: Rohan–Meera, Rohan–Karan, and Meera–Karan. Checking the original circle, Rohan–Meera exists and Meera–Karan exists, but Rohan–Karan does not. That is 2 out of 3 possible pairs connected, so Aditi's clustering coefficient is 2/3 ≈ 0.67 — a fairly tight-knit friend group, the kind where everyone already knows everyone at a birthday party. Compare that to Karan, whose three friends are Aditi, Meera, and Priya: Aditi–Meera exists, but neither Aditi–Priya nor Meera–Priya does. Karan's clustering coefficient is only 1/3 ≈ 0.33, consistent with his role as a bridge between two groups that barely know each other directly. Low clustering around a node is often a warning sign — or a welcome sign, depending on what you are looking for — that the node is a broker rather than a member of one cohesive clique.
Where This Shows Up: Graphs Beyond Friend Circles
Every idea in this chapter — degree, shortest paths, bridges, clustering — was demonstrated on a toy circle of six people, but the same mathematics runs, largely unchanged, on networks with hundreds of millions of nodes, and it already shapes daily life across India in ways that rarely get labeled "graph analysis."
When India went into lockdown in 2020, health authorities needed to trace everyone a newly diagnosed COVID-19 patient might have exposed. That is a shortest-path problem on a contact graph: an edge exists between two people if they were in close proximity, and BFS from the confirmed case identifies everyone within one, two, or three hops who needs testing or quarantine. India's Aarogya Setu app, launched in 2020, used Bluetooth proximity logging to help build exactly this kind of contact graph at national scale.
Banks and UPI payment processors watch transaction graphs for fraud in a similar spirit. A normal transaction graph looks like our friend circle: a sprawling, sparse, mostly tree-like web of payments for rent, groceries, and shopping. A money-laundering ring, by contrast, often shows up as an unusually dense, closed loop — account A pays B, B pays C, C pays back to A, over and over, in a pattern that looks nothing like ordinary spending. Graph analysis flags these tight, suspicious clusters automatically, the same way we flagged Karan as structurally unusual, except here, being structurally unusual is exactly what investigators are hunting for.
Every "People You May Know" suggestion on a professional network, or "Suggested for You" account on a photo-sharing app, is degree-and-path analysis in action: the platform looks two hops out from you, at your friends' friends, ranks candidates by how many mutual connections you share, and surfaces the strongest ones. And centrality itself scales far beyond people: Google's original PageRank algorithm, built by Larry Page and Sergey Brin in 1998, ranked web pages by treating every hyperlink as a directed edge and calculating which pages were linked to by other important pages — a direct descendant of the same "importance from your position in the graph" idea that separated Karan from Aditi in our tiny circle.
Back to the Group Chat
Go back to that Grade 10 WhatsApp group from the start of this chapter. Every one of its members has a degree. Some of them are bridges holding two friend clusters together, whether they realize it or not. Somewhere in your city, and somewhere across the country, a short chain of friendships probably connects you to almost anyone else with a phone. None of this requires mathematics beyond what fits in this chapter: nodes, edges, a queue, and a handful of careful sums. The next time an app tells you it found someone you "may know," or a bank flags a suspicious transaction pattern, or contact tracers ask who you met last week, remember that underneath the interface, someone modeled a version of exactly the six-person circle you just built, computed exactly the numbers you just computed, and asked the same three questions social network analysis always asks: who is connected to whom, how far apart are they, and who is quietly holding the whole thing together.
Practice Exercises
Now it is time to practice! Complete these challenges to solidify your understanding:
- Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
- Exercise 2: Find a real-world example where social networks analysis: understanding connection is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
- Exercise 3: Create a mind-map connecting social networks analysis: understanding connection to at least 3 other topics you have studied.
Key Takeaways — Summary and Recap
Let us recap what we covered: the core ideas behind social networks analysis: understanding connection, how they connect to real-world applications, and why they matter for your journey in computer science. Remember these key points as you move forward. For competitive exam preparation (CBSE, JEE, BITSAT), focus on understanding the WHY behind each concept, not just the WHAT.