learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Algorithm Selection

Select an algorithm and generate steps to begin visualization

Barabási–Albert Model Visualizer

The rich get richer: how hubs grow

Grows a network one vertex at a time: each newcomer links to m vertices picked in proportion to their degree, so hubs emerge and the degrees follow a power law

Time: O(n · m)
Space: O(n · m)
Use Case: Models of the web, citation and social networks, synthetic test graphs, scale-free networks
Showing the example graph for this algorithm.
Edges per new vertex (m)

The drawn edges are the starting network. Vertices without edges join one by one, in label order.

Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Barabási–Albert Model (Preferential Attachment)

The Barabási–Albert model grows a random network one vertex at a time. Each newcomer links to m existing vertices, picked with probability proportional to their degree, so a vertex with twice as many links is twice as likely to win the next one. Albert-László Barabási and Réka Albert proposed it in 1999 to explain why so many real networks, from the web to citation and social networks, have a few huge hubs and a long tail of vertices with few links. Two ingredients are enough: growth, because the network keeps getting new vertices, and preferential attachment, the rich get richer. The resulting degree distribution follows a power law, P(k) ∝ k^-3, unlike the bell shape of a purely random graph, which is why such networks are called scale-free.

How it works

The drawn edges form the seed network, a triangle in the example, and every vertex without edges joins later, one by one in label order. When a vertex arrives, the visualizer computes each existing vertex's chance, its degree divided by the sum of all degrees, writes it in a badge, then draws m distinct targets with those chances and adds the new edges. Vertex size follows degree, so the hubs swell as the network grows, and the panel draws the degree distribution. With m = 2 and 13 vertices joining the triangle A, B, C, the final network has 16 vertices and 29 edges. B ends with 10 links, D with 7 and A with 6, while 9 vertices keep only the 2 links they arrived with. The mean degree is 3.6, yet most vertices are below it: a long tail in miniature.

Applications

The model is the standard explanation and generator for scale-free networks. It is used to create realistic synthetic graphs for testing algorithms and databases, to study how the internet, power grids and protein interaction networks respond to failures and attacks, since scale-free networks shrug off random failures but break quickly when their hubs are removed, and to model how epidemics and rumours spread, where hubs act as super-spreaders and vaccinating them helps most. Citation counts, where cited papers attract more citations, and follower counts on social platforms behave the same way. NetworkX, igraph and other libraries provide a barabasi_albert_graph generator, and extensions add fitness, ageing or clustering to match particular networks better.

Pseudocode

Growth plus preferential attachment, one newcomer at a time.

BarabasiAlbert(G0, n, m):
    G = G0                                      // the seed network
    while G has fewer than n vertices:
        P(u) = deg(u) / sum of all degrees, for every u in G
        T = m distinct vertices drawn with the chances P
        add a new vertex v and an edge from v to every vertex of T
    return G

Drawing from a list that holds each vertex once per edge end gives the same chances in O(1) per draw, since a vertex of degree k appears k times. That keeps the model at O(n · m). The visualizer computes the chances explicitly so that each newcomer's odds can be shown.

Worked example, step by step

The example loaded on this page, with m = 2.

Example graph: A triangle A, B, C as the seed and 13 vertices D to P without edges, which join in that order.

  1. D joins. The three seed vertices all have degree 2, so each has a chance of 33%. D links to B and A.
  2. E joins. Degrees are now A 3, B 3, C 2 and D 2, a sum of 10: B has 30%, D 20%. E links to D and B.
  3. An early lead. B keeps winning: F, H, I, J, L and N all link to it. When J arrives, B alone holds 23% of the chances.
  4. Last arrivals. O links to A and D, P to G and D. Latecomers mostly link to vertices that are already big.

16 vertices and 29 edges. The hubs are B with 10 links, D with 7 and A with 6, while 9 vertices keep only the 2 links they arrived with. The mean degree is 3.6, yet most vertices lie below it.

Complexity, and where it comes from

Time: O(n · m) · Space: O(n · m)

Each newcomer adds m edges. With the list of edge ends, each draw costs O(1), with a redraw when a vertex repeats, so the model runs in O(n · m) time and stores its n · m edges. Computing every chance for each newcomer, as the visualizer does, costs O(n) per vertex and O(n²) in all, which is fine for small graphs.

When to use Barabási–Albert Model (Preferential Attachment), and when not to

Other random graph models.

AlternativePrefer it whenCost
Erdős–RényiEdges should be independent, each present with probability p. Degrees follow a Poisson distribution with no hubs.O(n + m)
Configuration modelA given degree sequence must be matched exactly, for instance one measured on real data. Havel–Hakimi checks that the sequence is graphical.O(m)
Watts–StrogatzHigh clustering and short paths are wanted, without hubs. A ring lattice is rewired at random.O(n · k)

Common pitfalls

  • Choosing the same target twice. The m targets must be distinct, otherwise the newcomer gets parallel edges and fewer neighbours. Draw again when a vertex repeats.
  • A seed with isolated vertices. A vertex of degree 0 has chance 0 and can never be chosen. The seed needs at least one edge on every vertex, and m cannot exceed the number of vertices already present.
  • Expecting a clean power law on a small graph. The k^-3 law describes large networks. With 16 vertices the tail is only a hint, and even with thousands, a straight line on a log-log plot is a weak test: use maximum likelihood fits.

Frequently asked questions

Why k^-3?
In the continuum approximation a vertex that arrived at time tᵢ has degree m·√(t / tᵢ) at time t. Counting the vertices whose degree exceeds k gives P(k) = 2m² / k³, so the exponent is 3 whatever m is.
Are real networks really scale-free?
Many have heavy-tailed degrees, but a 2019 study by Broido and Clauset found strict power laws to be rare. Preferential attachment remains the standard explanation for hubs, and real networks also need fitness, ageing or limits on degree.
What happens with m = 1?
Each newcomer adds one edge, so a tree seed stays a tree, connected and without cycles. Hubs still appear, and the tree looks like a star of stars.

Related algorithms: Havel-Hakimi, Clustering Coefficient, PageRank, k-Core Decomposition, Independent Cascade (Spread)

Built by Mohammed Islam HadjoudjWork with me

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 16
Edges: 3