r/computerscience • u/Snoo-16806 • Mar 13 '25
Help Graph theory and its application
Graph theory in real world applications
I've been interested lately in graph theory, I found it fun but my issue is that I can't really formulate real world applications into graph theory problems. I would pick a problem X that I might think it can be formulated as a graph problem, If I make the problem X so simple it works but as soon as I add some constraints i can't find a way to represent the problem X as a graph problem that is fundamental in graph theory.. I want to use the fundamental graph theories to resolve real world problems. I am no expert on the field so it might be that it's just a skill issue
33
u/cachehit_ Mar 13 '25
Are you asking what real-world things graph theory is used for? In that case, some easy answers: compilers, networking (routing), machine learning, and maps (e.g., google maps).
16
u/BrupieD Mar 13 '25
If you swap out the term "graph theory" with "networks," you might see a lot more practical applications.
Many data structures store data in ways that are easily descibed as graph structures. Wherever you have a structure that is hierarchical, nested, or connected, you can represent it as a graph. Social networks are graphs. The basics of graphs involve checking connections (are you friends?), directedness (I follow Sue, but does Sue follow me?), and weightedness (how many messages do these two nodes/people exchange).
I'm learning about graph algorithms now and am amazed at how much these ideas generalize to various programming topics.
7
u/a_cloud_moving_by Mar 14 '25
I think it’s important to realize that graphs are very, very general mathematical structures. Other people mentioning applications where graphs are usually applied (networks, etc.) but those are well known because graph algorithms apply well in those domains.
But graphs are super general. It is a set of unique—or non-unique— elements with relationships between none, some, or all of them.
Take permutations of 3 digits (000, 123, 574, etc.) If “adjacent” elements means one digit changes (e.g 000 is adjacent to 001, 010, etc.) and you then draw it out…you get a pretty cool graph! It forms kind of a honeycomb. Assuming modulus, it wraps around too. This doesn’t mean that people usually think of graphs first when discussing permutations, but enumerating permutations could easily be seen as a graph traversal problem if you describe it in this way.
I guess what I’m saying is, when people talk about “real-world” uses of graph theory they tend to lean on domains where graph theory is visually obvious (a social network) or where graph theory was famously used to solve a hard problem (fingerprint identification). But don’t let that fool you. Graphs are everywhere. Anything can be described as graph. As long as there is a set of elements and some way of describing a relationship between those elements.
EDIT: fixed some wording
5
u/beeskness420 Mar 14 '25
If you can’t directly model your problem in terms of paths, matchings, flows, trees, independent sets, dicuts, etc, then you can still probably define your problem as a linear program where the skeleton of the constraint polytope forms a graph and following edges to an optimal node is the simplex method.
Even if you have an NP-Complete problem that isn’t naturally a graph question then there are countless polytime reductions to any other NPC graph problem. Presumably the same works for reductions between NP-Hard problems generally.
Whether this is a useful view point really depends on the problem.
4
u/neuralengineer Mar 13 '25
Check Newman's Networks book.
3
u/nuclear_splines PhD, Data Science Mar 14 '25
Graphs are used all over the place! Recommendation algorithms, ecology, ontologies, traces of human collaboration (for example, you can view git commit histories as bipartite graphs of contributors and files they've modified, or you can view chess tournaments as directed graphs of players defeating other players), belief networks, constraint satisfaction in governance, mobility data (for everything from urban planning to public health to archaeology), and much more! Network science is an interdisciplinary field that interacts with a wide array of other academic disciplines.
3
u/Character_Cap5095 Mar 14 '25
In undergrad I did research on studying cascading failures in power grid networks (which were just weighted directed graphs).
2
u/No-Treat6871 Mar 14 '25
Social network analytics and computational social science.
2
u/Historical_Cook_1664 Mar 14 '25
Traveling Salesman is NP-complete. Therefore, almost any computational problem should be able to be transformed into a graph theory problem...
1
u/SalocinS Mar 16 '25
My all time favorite application of Graph theory is the Rubik’s cube! Think of a solved rubik’s cube as the starting Node, you can move to other states of the cube by moving the Front, Back, Left, Right, Bottom and Top layers. Each move is an edge to another node that represents a unique state of the rubik’s cube. The graph of all possible states of the rubik’s cube is absolutely massive, but in theory it turns the problem of solving the Rubik’s cube into finding the shortest way to traverse the graph from your scrambled node to the solved node.
1
u/[deleted] Mar 16 '25
Graphs are extremely fundamental to how we model the world computationally speaking. Anything that you can think of that has a “network” can be modeled as a graph. Any 2 concepts that have a relationship between them can be theoretically modeled as graphs. You can even sort with graphs!!
Even for sorting you could in theory build a big directed graph from 1 to N where N is the biggest number in your unsorted array then all you have to do is traverse the graph using dfs until you reach the last node (N) and then for every node that you find in the graph check whether that number exists in the array (you can use an OrderedSet for this)
This would be a pretty bad way to sort but the point is that graphs are useful for pretty much anything and everything.
Learn to use graphs in everything first then you’ll realize there’s much better ways to do things and then opt for those instead.
0
u/power10010 Mar 14 '25
Thats why these things are for engineers with real problems
2
u/[deleted] Mar 15 '25
[removed] — view removed comment