Graphs Flashcards
What are graphs?
A general, non-linear data structure consisting of nodes (vertices) and edges between nodes.
G = (V, E)
Undirected Graph
There is no order to how the edges connect vertices.
Directed Graph
Each edge has a source vertex and target vertex.
Loop
An edge that connects a vertex to itself.
Path
A sequence of vertices such that each adjacent pair of vertices are connected by an edge.
Cycle
A simple path with no repeated vertices or edges other than the starting and ending vertices.
Directed Cycle
A cycle in a directed graph.
Weighted Graph
Has values on its edges.
Connected Graph
A graph that has a path between every pair of distinct vertices.
Complete Graph
A graph that has an edge between every pair of distinct vertices.
Disconnected Graph
Any graph that lacks a path between at least one pair of vertices.
Adjacent Vertices
Undirected: joined by an edge.
Directed: A is adjacent to B if the edge begins at B and ends at A.
Max # of edges (undirected)
n(n-1)/2
Max # of edges (directed)
n(n-1)
Adjacency Matrix
Array implementation of ADT graph. A square (n x n) grid of true/false values representing edges of the graph.