Takeaways
- A graph is a series of nodes ("Vertices") connected by edges
- A graph G = ( V, E ) where V is the set of vertices, and E is the set of edges in the graph
- A graph can be undirected or directed (one-way edges)
- A graph can be weighted, where each edge has a cost
- A path is a sequence of connected edges (no loops)
- A Cycle is a sequence of connected edges that form a loop
- G1 = G2 iff V1 = V2 and E1 = E2
- The degree of a vertex is the amount of edges that touch the vertex
- We represent graphs using an Adjancency List
- Graphs can be traversed using Depth First and Breadth First. All nodes will be visited as long as there are no unconnected parts.
- As we are traversing a graph, we need to keep track of which nodes have been visited to avoid infinite loops
- If depth first is done on a starting vertex, depth first will find a path from the start vertex to all other vertices in the graph (not optimal paths)
Code
March 11th code is a basic graph representation using an adjacency list. There are methods for traversing the graph and finding a path in the graph. UndirectedGraphHashMap is a graph where Edges represent the vertices (states) that share a border.