Graphs Flashcards

(50 cards)

1
Q

What is a graph in data structures?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two main types of graphs?

A

Directed graphs (digraphs) and undirected graphs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a directed graph?

A

A graph in which edges have a direction, indicating a one-way relationship from one vertex to another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an undirected graph?

A

A graph where edges do not have direction; connections between vertices are bidirectional.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a weighted graph?

A

A graph where each edge is assigned a numerical value or weight, often representing cost, distance, or time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an unweighted graph?

A

A graph where all edges are treated equally, with no associated weight.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an adjacency matrix?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an adjacency list?

A

A collection of lists or arrays where each vertex stores a list of its neighboring vertices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When is an adjacency list preferred over an adjacency matrix?

A

When the graph is sparse (contains relatively few edges), since it saves space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a sparse graph?

A

A graph where the number of edges is much less than the maximum possible, typically closer to O(V) than O(V²).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a dense graph?

A

A graph where the number of edges is close to the maximum number of possible edges, near O(V²).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a cycle in a graph?

A

A path of edges and vertices in which a vertex is reachable from itself without repeating any edges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an acyclic graph?

A

A graph with no cycles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a DAG?

A

A Directed Acyclic Graph, meaning it has directed edges and no cycles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a path in a graph?

A

A sequence of vertices connected by a series of edges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a connected graph?

A

An undirected graph where there is a path between every pair of vertices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a strongly connected graph?

A

A directed graph in which there is a path from every vertex to every other vertex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a weakly connected graph?

A

A directed graph that becomes connected if all its edges are treated as undirected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a tree in graph theory?

A

An undirected graph that is connected and acyclic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How is a tree related to graphs?

A

A tree is a special case of an undirected graph with no cycles and exactly V - 1 edges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the degree of a vertex in an undirected graph?

A

The number of edges connected to the vertex.

22
Q

What is the in-degree of a vertex in a directed graph?

A

The number of edges coming into the vertex.

23
Q

What is the out-degree of a vertex in a directed graph?

A

The number of edges going out from the vertex.

24
Q

What is a self-loop in a graph?

A

An edge that connects a vertex to itself.

25
What is a multigraph?
A graph that may contain multiple edges (parallel edges) between the same pair of vertices.
26
What is a simple graph?
A graph with no self-loops and no more than one edge between any pair of vertices.
27
What is graph traversal?
The process of visiting each vertex in a graph, usually using either BFS or DFS.
28
What is Breadth-First Search (BFS)?
A graph traversal algorithm that explores vertices in layers, using a queue to visit neighbors level by level.
29
What is Depth-First Search (DFS)?
A graph traversal algorithm that explores as far as possible along each branch before backtracking, using a stack or recursion.
30
What data structure does BFS use?
A queue.
31
What data structure does DFS typically use?
A stack or the program’s call stack through recursion.
32
What is the time complexity of BFS or DFS using an adjacency list?
O(V + E), where V is the number of vertices and E is the number of edges.
33
What is the time complexity of BFS or DFS using an adjacency matrix?
O(V²), since all vertex pairs must be checked.
34
What is topological sorting in a graph?
A linear ordering of vertices such that for every directed edge u → v, vertex u appears before v.
35
What kind of graph supports topological sort?
A Directed Acyclic Graph (DAG).
36
What is Dijkstra’s algorithm used for?
Finding the shortest paths from a single source vertex to all other vertices in a graph with non-negative edge weights.
37
What is Bellman-Ford algorithm used for?
Finding shortest paths from a source vertex in a graph that may contain negative edge weights.
38
What is Floyd-Warshall algorithm used for?
Computing shortest paths between all pairs of vertices in a weighted graph.
39
What is Prim’s algorithm used for?
Constructing a Minimum Spanning Tree (MST) from a connected, weighted, undirected graph.
40
What is Kruskal’s algorithm used for?
Constructing a Minimum Spanning Tree by sorting all edges and adding them in order, avoiding cycles.
41
What is a Minimum Spanning Tree (MST)?
A subset of edges that connects all the vertices with the minimum possible total edge weight and no cycles.
42
Can a directed graph have an MST?
No, MSTs are only defined for undirected graphs.
43
What is a bipartite graph?
A graph whose vertices can be divided into two sets such that no two vertices within the same set are adjacent.
44
How can you check if a graph is bipartite?
Using BFS or DFS to try to 2-color the graph without conflicts.
45
What is the shortest path problem?
The problem of finding the path with the smallest total weight between two vertices.
46
What is a key difference between BFS and DFS for shortest path?
BFS finds the shortest path in unweighted graphs; DFS does not guarantee shortest paths.
47
What is a bridge in a graph?
An edge whose removal increases the number of connected components in the graph.
48
What is an articulation point?
A vertex whose removal increases the number of connected components in the graph.
49
What is the graph coloring problem?
The problem of assigning colors to vertices so that no two adjacent vertices share the same color.
50
What is the chromatic number of a graph?
The minimum number of colors needed to color the graph under the graph coloring constraint.