Home/Notes/Graphs
Board Exam Notes

Graphs Notes

Questions

3 questions per exam

Difficulty

Medium-Hard

Importance

High yield for University Semester Exams and GATE/PSU screening

Overview

Graphs are non-linear data structures consisting of vertices and edges that model complex relationships between objects in real-world systems. Mastering this topic is essential for academic exams because it forms the backbone of network analysis, pathfinding, and optimization problems. A successful aspirant must focus on how structural representation impacts algorithm efficiency and traversal performance.

Graph Representation

Graphs are represented in memory using two primary methods, each with distinct space and time complexity trade-offs based on edge density. Choosing the correct structure is a frequent point of inquiry in both written exams and design-based viva questions.

  • Adjacency Matrix: O(V^2) space, best for dense graphs.
  • Adjacency List: O(V + E) space, efficient for sparse graphs.
  • Edge List: Useful for algorithms like Kruskal's that sort edges.
  • Incidence Matrix: Represents relationships between vertices and edges.
  • Space complexity is proportional to the number of edges for sparse representations.

Graph Traversals: BFS & DFS

Traversal algorithms systematically visit all nodes in a graph, providing the foundation for searching and connectivity analysis. These algorithms are frequently asked in exams to trace their execution flow on specific graph diagrams.

  • BFS utilizes a Queue data structure for FIFO processing.
  • DFS utilizes a Stack or Recursion for LIFO processing.
  • BFS is optimal for finding the shortest path in unweighted graphs.
  • DFS is ideal for cycle detection and topological sorting.
  • Time complexity for both is O(V + E) using adjacency lists.

Shortest Path Algorithms

Shortest path algorithms are critical for optimization problems, determining the minimum cost to reach a destination. Understanding the conditions under which Dijkstra’s algorithm fails compared to Bellman-Ford is a common conceptual question.

  • Dijkstra's Algorithm: Greedy approach, fails with negative edge weights.
  • Bellman-Ford: Dynamic programming, handles negative edges, O(V*E) complexity.
  • Floyd-Warshall: All-pairs shortest path algorithm with O(V^3) complexity.
  • Dijkstra's implementation using a Priority Queue yields O(E log V).
  • Relaxation is the core operation for minimizing path distance.

Exam Tip

When asked for algorithm complexity, always specify whether you are assuming the graph is represented by an adjacency list or a matrix, as this is the primary differentiator for high-scoring answers.

Common Mistakes

  • Confusing the time complexity of adjacency matrix versus adjacency list representations.
  • Attempting to use Dijkstra's algorithm on graphs that contain negative edge weights.
  • Forgetting to mark visited nodes, which leads to infinite loops in cyclic graphs during DFS/BFS.

More Revision Notes

Ready to test yourself?

Play topic-wise Graphs questions in Aspirant Arcade — gamified MCQ practice.

Download Free