To change between adjacency lists and adjacency matrices, you can follow these simple steps:
Converting from an Adjacency List to an Adjacency Matrix:
First, create a square grid (matrix) with rows and columns. Here, is the number of points (or vertices) in your graph. Start with all the spaces set to zero.
Next, for each connection (or edge) in your list that goes from point to point , change the spot in the matrix at row and column to 1. If your graph has weights, put the weight instead of 1.
Converting from an Adjacency Matrix to an Adjacency List:
Start by making an empty list for each point (or vertex).
Then, look at each space in the matrix. If the space at row and column is not zero (meaning there's a connection), add to the list for .
The process of changing from a matrix to a list takes time based on , while changing from a list to a matrix takes time based on . Here, represents the number of connections (or edges).
To change between adjacency lists and adjacency matrices, you can follow these simple steps:
Converting from an Adjacency List to an Adjacency Matrix:
First, create a square grid (matrix) with rows and columns. Here, is the number of points (or vertices) in your graph. Start with all the spaces set to zero.
Next, for each connection (or edge) in your list that goes from point to point , change the spot in the matrix at row and column to 1. If your graph has weights, put the weight instead of 1.
Converting from an Adjacency Matrix to an Adjacency List:
Start by making an empty list for each point (or vertex).
Then, look at each space in the matrix. If the space at row and column is not zero (meaning there's a connection), add to the list for .
The process of changing from a matrix to a list takes time based on , while changing from a list to a matrix takes time based on . Here, represents the number of connections (or edges).