Data Structures · Graph Representation and Traversals
Introduction to Graphs and Their Applications
Overview
A graph is a structure made of a set of vertices (nodes) and a set of edges (links between vertices); graph theory is the study of such structures and their properties.
Graph theory was historically not considered part of computer science, but the Internet and social networks made it central to the field, because both the World Wide Web and social networks can be modeled as graphs.
Key concepts
- Graph: A structure represented as a set of vertices (nodes) and a set of edges (links between vertices).
- Graph theory: The study of graphs and their properties.
- World Wide Web as a graph: Every web page is a node (vertex); a link from one web page to another web page is an edge. The entire World Wide Web can therefore be modeled as a graph.
- Social network as a graph: A person is a node, all of that person's friends are also nodes, and there is a link (edge) between the person and each friend.
- General representation: A graph is generally represented as a set of vertices and a set of edges.

Drawing the diagram…
How it works
- Earlier, graph theory was not considered part of computer science — it was kept aside and not studied by computer science engineers or anyone from computer science.
- With the advent of the Internet (since the 1980s), there has been great interest in graph theory, especially from people in computer science.
- The World Wide Web is modeled as a graph: web pages are nodes and links between pages are edges.
- Social networks (especially Facebook and other social networking sites) are also represented as graphs: people are nodes and friendships are edges.
- Once the web (or a social network) is a graph, its various properties can be explored; search based on these properties becomes relevant, and search times (and everything else) can be improved.
Revision summary
- A graph = set of vertices + set of edges.
- Two major real-world applications that drove graph theory into computer science: the World Wide Web (web page = node, hyperlink from one page to another = edge) and social networks such as Facebook (person/profile = node, friendship = edge).
- Graph theory was historically outside computer science; the Internet (from the 1980s) and social networks made it central to computer science.
- Modeling the web or a social network as a graph lets us study graph properties and improve search.
Previous-year exam insights
- Handshaking lemma: the sum of the degrees of all vertices of any undirected graph equals twice the number of edges, i.e. Σdeg(v) = 2|E|.
Asked inGATE 2017 - A tree with n vertices has exactly n−1 edges, is connected, and has no cycles; hence the sum of degrees of all its vertices is 2(n−1).
Asked inGATE 2017UGC NET 2006 - Every tree is a bipartite graph (trees have no odd cycles), and a tree is a connected acyclic graph.
Asked inUGC NET 2006 - A graph is bipartite if and only if it contains no cycle of odd length; equivalently its vertices can be split into two sets with every edge crossing between the sets.
Asked inUGC NET 2006 - In any graph the number of vertices of odd degree is even (a consequence of the handshaking lemma).
- A tree on n ≥ 2 vertices has at least two vertices of degree 1 (leaves); a connected graph with n vertices and n−1 edges is necessarily a tree.