VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.16 of 16 in this module Unrolled Pro

Find Connected Users in an Interaction Graph

Turn an interaction log into a user graph and answer neighbourhood questions: who is within k hops, which community a user belongs to, and which non-friends share the most mutual friends. From scoring every other user by intersecting friend sets (O(n · d)) or squaring the adjacency matrix (O(n³)), to a two-hop walk from the user that counts mutual friends only where they exist (O(Σ friend degrees)), then a heap for the top k. Then high-degree hubs, k-hop neighbourhoods with BFS, weighted interactions, and neighbour sampling as used by graph neural networks.

about 10 min 3 Python examples 2 quick checks

Problem. An interaction log lists pairs of users who interacted (messaged, co-edited, followed each other). Treat it as an undirected graph. For a user u, recommend the top k users u is not yet connected to, ranked by the number of mutual connections (friends of friends), ties broken by user id.

text
log: (ana, bo) (ana, cy) (bo, dee) (cy, dee) (cy, eli) (bo, eli) (dee, fay)
recommend(ana, k = 2)   →   [dee (2 mutual: bo, cy), eli (2 mutual: bo, cy)]

Mutual-friend counting is the classic "people you may know" signal, and the neighbourhood questions around it (k-hop reach, communities) are BFS and connected components from lessons 11.1 and 11.8, on a graph where a few users have enormous degree.

ML context. Recommender systems generate candidates from the user graph (friends of friends, items co-interacted by similar users) before a model ranks them. Graph neural networks compute each node's representation from its sampled k-hop neighbourhood. Fraud and abuse teams look at connected components of accounts linked by interactions. Each needs fast neighbourhood queries on a graph with millions of nodes and heavy-tailed degrees.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Find Connected Users in an Interaction Graph"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee