Graph Theory37 sections · 1633 units
Open in Course

Intro

Dynamic changes

Imagine you are building a social network from scratch. Initially, you have NN people, but zero friendships. Everyone is a stranger.

Then, events happen in real-time: "User 11 becomes friends with User 22." "User 33 becomes friends with User 44." "User 11 becomes friends with User 33." After every event, you might want to ask: "Are User 22 and User 44 connected?" Running BFS after every single added edge is too slow (O(N+E)O(N+E) every time). You need something faster.