GraphsLesson 32Free preview
Graphs Implementation
This lesson is part of DSA · All levels
Summary
A graph can be implemented with an adjacency matrix in the form of a two-dimensional array or an adjacency list in the form of a list of neighbors of each node. The matrix is easy to check for the presence of sides but memory drain for graphs is rare, while the list is more economical and efficient for searching. The representation option determines the speed and memory of the next algorithm.
Key points
- The adjacency matrix uses memory, side checks
- Adjacency list using memory, suitable for rare graphs
- The Matrix makes it easy for algorithms like Floyd-Warshall.
- The list is more commonly used for BFS and DFS.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.