Graphs Flashcards
What is a ‘graph’?
A set of vertices and edges
What does it mean for two vertices to be (adjacent)?
Two vertices are adjacent if there exists an edge connecting them.
What is a ‘Weighted Graph’?
A graph in which a values is associates w/ each edge.
What is a ‘Directed Graph’?
A graph in which every edge has a direction associated with it.
What is a ‘Dependency Graph’?
A data structure formed by a directed graph that describes the dependency of an entity in the system on the other entities of the same system.
What are the two ways in which graphs are represented?
- Adjacency Matrix
- Adjacency List
What is the runtime for determining if there is an edge between two vertices?
- Adjacency Matrix: Theta(1)
- Adjacency List: O(d)/O(V)
where d is the degree of the vertex.
What is the runtime for determining all vertices adjacent to a given vertex?
- Adjacency Matrix: Theta(V)
- Adjacency List: O(d)/O(V)
where d is the degree of the vertex.
What are the space requirements for each representation of a graph?
- Adjacency Matrix: Theta(V^2)
- Adjacency List: Theta(V+E)
When should you use an Adjacency Matrix?
- Small Graphs
- Dense Graphs
When should you use an Adjacency List?
- Large Graphs
- Sparse Graphs
What is BFS used for?
BFS is used for finding the shortest path on an unweighted graph.
What type of data structure does a BFS algorithm use?
The BFS algorithm uses a queue.
What if the count of an index in BFS is not 0?
This means that there is an unvisited layer.
What is a DFS algorithm used for.
The most fundamental algorithm used to explore nodes & Edged of a graph.