Introduction to Graphs

Learn about graphs and their types.

What are graphs?

Graphs are mathematical structures that represent pairwise relationships between objects. A graph is a flow structure that represents the relationship between various objects. It can be visualized by using the following two basic components:

  • Nodes: These are the most important components in any graph. Nodes are entities whose relationships are expressed using edges. If a graph comprises 2 nodes, A and B and an undirected edge between them, then it expresses a bi-directional relationship between the nodes and the edge.
  • Edges: Edges are the components that are used to represent the relationships between various nodes in a graph. An edge between two nodes expresses a one-way or two-way relationship between the nodes.

Applications of graphs

  • Google Maps: To find a route based on the shortest route/Time.
  • Social Networks: Connecting with friends on social media, where each user is a vertex, and when users connect they create an edge.
  • Web Search: Google, to search for webpages, where pages on the internet are linked to each other by hyperlinks, each page is a vertex and the link between two pages is an edge.
  • Recommendation System: On eCommerce websites relationship graphs are used to show recommendations.

The types of graphs?

There are mainly four classifications of graphs:

  • Undirected: An undirected graph is one in which all the edges are bi-directional, i.e., the edges do not point in any specific direction.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.