Graphs Flashcards
What is a graph
Set of nodes connected by edges
What is a unweighted graph
All edges cost 0 to travel
What is a weighted graph
Each edge has a cost to travel
What is a undirected graph
Each edge is bi-directional
What is a directed graph
Each edge is one-way
How does an adjacency matrix represent a graph
Each row and column represent a node.
Item at [row, column] represents a connection.
In an unweighted graph this number is 1.
In a weighted graph the number is the weight
How does an adjacency list represent a graph
A list of nodes is created, and each node contains a list of connected nodes.
Advantage and disadvantage of using a adjacency matrix
Advantage: Easy to work with, adding an edge is easy
Disadvantage: Can have lots of wasted space if used with a sparse graph
Advantage and disadvantage of using a adjacency list
Advantage: Easy way to store large graphs as only stores information about connections that exist.
Disadvantage: It is slow to search through