Graphs Flashcards
(50 cards)
What is a graph in data structures?
A graph is a non-linear data structure consisting of a set of vertices (nodes) and a set of edges that connect pairs of vertices.
What are the two main types of graphs?
Directed graphs (digraphs) and undirected graphs.
What is a directed graph?
A graph in which edges have a direction, indicating a one-way relationship from one vertex to another.
What is an undirected graph?
A graph where edges do not have direction; connections between vertices are bidirectional.
What is a weighted graph?
A graph where each edge is assigned a numerical value or weight, often representing cost, distance, or time.
What is an unweighted graph?
A graph where all edges are treated equally, with no associated weight.
What is an adjacency matrix?
A 2D array used to represent a graph, where each cell (i, j) indicates whether an edge exists (and possibly its weight) between vertex i and vertex j.
What is an adjacency list?
A collection of lists or arrays where each vertex stores a list of its neighboring vertices.
When is an adjacency list preferred over an adjacency matrix?
When the graph is sparse (contains relatively few edges), since it saves space.
What is a sparse graph?
A graph where the number of edges is much less than the maximum possible, typically closer to O(V) than O(V²).
What is a dense graph?
A graph where the number of edges is close to the maximum number of possible edges, near O(V²).
What is a cycle in a graph?
A path of edges and vertices in which a vertex is reachable from itself without repeating any edges.
What is an acyclic graph?
A graph with no cycles.
What is a DAG?
A Directed Acyclic Graph, meaning it has directed edges and no cycles.
What is a path in a graph?
A sequence of vertices connected by a series of edges.
What is a connected graph?
An undirected graph where there is a path between every pair of vertices.
What is a strongly connected graph?
A directed graph in which there is a path from every vertex to every other vertex.
What is a weakly connected graph?
A directed graph that becomes connected if all its edges are treated as undirected.
What is a tree in graph theory?
An undirected graph that is connected and acyclic.
How is a tree related to graphs?
A tree is a special case of an undirected graph with no cycles and exactly V - 1 edges.
What is the degree of a vertex in an undirected graph?
The number of edges connected to the vertex.
What is the in-degree of a vertex in a directed graph?
The number of edges coming into the vertex.
What is the out-degree of a vertex in a directed graph?
The number of edges going out from the vertex.
What is a self-loop in a graph?
An edge that connects a vertex to itself.