Media are best understood as a competition for attention on internet-connected screens. Phones, tablets, laptops, monitors, TVs—it's all just glass.

Fans of the Game of Thrones books and TV series have long quarreled over who the true hero of the story is. Daenerys? Tyrion? Jon Snow? Hodor? Every time a character seems to be developing into a protagonist, he or she is brutally killed (video). Such is the perilous existence of the major players in the world of the wildly popular HBO series—when you play the game of thrones, you win or you die.

But several main characters remain. And in order to determine the one true hero of them all—the one most vital to the story, with the most important connections to other characters—we must turn to math.

Andrew J. Beveridge, an associate professor of mathematics at Macalester College, and Jie Shan, an intrepid undergraduate, decided to turn the world of the Game of Thrones books into a social network using network science, a branch of applied graph theory that draws from several disciplines, including economics, sociology, and, computer science, to examine how information flows from one thing to another.

The books and HBO fantasy series, with their massive cast of characters, various shifting allegiances, and intricate relationship dynamics, were a perfect fit to be studied mathematically.

“This is a fanciful application of network science,” Beveridge told Quartz. “But it’s the kind of accessible application that shows what mathematics is all about, which is finding and explaining patterns.” Their research, entitled “Network of Thrones,” is published in the Mathematical Association of America’s publication, Math Horizons (pdf).

The pair started by connecting characters every time they “interacted” in the third book of the series, A Storm of Swords. Whenever two characters appeared within 15 words of one another, a link (or “edge”) was added between them. The links are weighted based on how often the two characters appeared in close proximity. Characters don’t necessarily have to be friends to be linked—which is a good thing because there are few true friendships in the series.

Andrew J. Beveridge and Jie Shan The various communities of “Game of Thrones,” visualized using network science.

The resulting network structure (above) broke the characters into extremely accurate communities that show the geographical, familial, and even adversarial ties between them.

“We didn’t tell it what the communities were, the network actually tells you what the communities are,” Beveridge said.

Then the mathematicians ranked the characters by several different measures. One, called degree centrality, simply ranks the characters by how many others they’re connected with. Other measures, like PageRank (the same algorithm that Google uses for its search engine), actually puts the characters into a feedback loop, rewarding them based on how important the people that they’re associated with are in the network.

Ranked first in every measure, save for one, was the same character: Tyrion, the sharp-witted, marginalized member of powerful house Lannister. In spite of his small size, Tyrion is mathematically the most important character in Game of Thrones.

Tyrion is followed by Jon Snow, the (former) head of the Night’s Watch and bastard son of Eddard Stark, and then Sansa Stark, one of Eddard’s daughters, who finds herself in several precarious situations throughout the story.

The results aren’t too surprising, given that Tyrion has the most point-of-view chapters in the book series, with 49. That said, the network experiment didn’t reflect the number of POV chapters per character exactly. For example, Arya Stark, Sansa’s younger sister, has the third most chapters with 34, but ranks behind Sansa in terms of network importance. To the chagrin of younger siblings everywhere, in this case, at least, big sister is just a little more valuable.

Daenerys Targaryen, the “Mother of Dragons” and true heir to the Iron Throne, is also very important. But her ranking is hindered a bit by being isolated on the continent Essos, away from most of the main action on Westeros. She’s still vital to the network, though, because the characters on Westeros she is connected to are very important, and all characters essentially must go through her in order to interact with others on Essos.

Beveridge argued that the network science can actually predict where the story is headed, citing Daenerys Targaryen’s connections as an example. (Indeed, her story really picks up two books later.)

“Daenerys really represents the future—you can see whats about to happen based on the people she’s linked with,” Beveridge said.

Outside this fantasy world, network science has several other (serious) applications. The United States National Security Agency, for example, uses it to study terrorist networks.