Skip to main content

Graph

This page provides introduction to graph data structure.

Overview

A graph is a collection of nodes connected by edges that represent relationships between entities. Graphs can be directed or undirected, and may be weighted or unweighted. Commonly used to model networks, graphs are versatile tools in areas like social networking, pathfinding, and dependency resolution.

Graph Traversals

There are 22 types of graph traversals:

  • Depth First Search(DFS)
  • Breadth First Search(BFS)

How to Spot These Problems

You can identify graph problems:

  • If the problem asks you to model relationships or connections between entities, such as social networks, roadmaps, or dependencies.
  • When you notice inefficiencies in operations like traversals, shortest path computations, or connectivity checks.
  • If the problem involves cycles, paths, or connected components, as these are common graph-related concerns.
  • If the solution requires optimization, such as finding the minimal spanning tree or the shortest path in a weighted graph.

Leetcode Problem Set