Introduction to Graph Data Structures
Graph Fundamentals
A graph is a collection of nodes called vertices and the connections between them called edges, denoted as .
An edge is a pair of vertices . Entities such as people, cities, or computers are represented by vertices, while edges represent their relationships.
Directed Graph (Digraph): A graph where every edge has a specific direction.
Undirected Graph: A graph where edges have no direction.
Graph Terminologies
Adjacent Vertices: Two vertices connected by an edge. In a directed graph, if is an edge, is adjacent to , and is adjacent from .
Degree: The number of edges incident to a vertex. The sum of the degrees of all vertices is equal to the number of edges.
Path: A sequence of vertices where consecutive vertices are adjacent.
Simple Path: A path in which no vertex is repeated.
Cycle: A simple path where the first and last vertices are the same.
Connected Graph: A graph where a path exists between every pair of vertices.
Complete Graph: A graph where there is an edge between every pair of vertices.
Tree and Forest: A tree is a connected graph with no cycles. A forest is a collection of trees.
Subgraph: A subset of vertices and edges that forms a graph. A connected component is a maximal connected subgraph.
Applications and Representations
Applications: Designing circuits to find the path of least resistance and modeling networks (roads, flights, or communications) to determine shortest paths.
Adjacency Matrix: An matrix where if an edge exists between node and node , and otherwise.
Adjacency Lists: A one-dimensional array of linked lists, where contains all nodes adjacent from vertex .
Graph Traversal Techniques
Depth-First Search (DFS):
Implements a "last visited, first to backtrack" strategy using a stack.
Rules: Visit an adjacent unvisited vertex, mark it as visited, display it, and push it onto the stack. If no adjacent unvisited vertex exists, pop from the stack.
Breadth-First Search (BFS):
Visits nodes level by level using a queue.
Rules: Visit an adjacent unvisited vertex, mark it as visited, display it, and insert it into the queue. If no adjacent unvisited vertex exists, remove the first vertex from the queue.
Questions & Discussion
Draw the directed graph corresponding to a given adjacency matrix (e.g., involving Boolean values True/False).
Draw the edge lists (adjacency lists) for a specific graph.
Determine the order of vertex visits for a depth-first search starting at vertex .
Determine the order of vertex visits for a breadth-first search starting at vertex .
Define the terms Edge, Vertex, Path, and Degree.