educative.io

Educative

Graph implementation must start from 0?

The first implementation of a graph using an adjacency list, it appears it only works for graphs starting at 0 where each vertice increments by 1. So you could NOT have a graph like:

    11
  /\    \
3   4    7

Is this by design just to be simple for the first intro to graph implementation?

Hi Ryan,

As mentioned in the course:
“The adjacency matrix is a two-dimensional matrix where each cell can contain a 0 or 1 .”

Hence the adjacency matrix only contains 0 or 1 and does work on other digits. And the adjacency list works the same and does not contain digits other than 0 and 1.