Graph Theory Introduction
- 56Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the key characteristic of an undirected graph?
56 questions
- 1
What is the key characteristic of an undirected graph?
Model answer
In an undirected graph, edges have no orientation: an edge from node u to node v is identical to an edge from v to u.
Explanation
Undirected graphs are the simplest type; edges are bidirectional, meaning the connection is symmetric.
- 2
In a directed graph, what do arrowheads on edges represent?
Model answer
Arrowheads indicate the direction of the edge: you can only travel from the start node to the end node, not the reverse.
Explanation
Directed edges create a one-way relationship, critical for modeling dependencies or flows.
- 3
Define a weighted graph and give an example of what edge weights might represent.
Model answer
A weighted graph has edges with numerical values (weights) representing cost, distance, quantity, or any other metric.
Explanation
Weights add a measure of cost or capacity to edges, enabling optimization problems.
- 4
What is the definition of a tree in graph theory?
Model answer
A tree is an undirected graph with no cycles. Equivalently, it has n nodes and n-1 edges.
Explanation
Trees are acyclic connected graphs, fundamental for spanning structures.
- 5
Distinguish between a rooted tree and an unrooted tree.
Model answer
A rooted tree has a designated root node, and edges either point away from (out-tree) or towards (in-tree) the root; an unrooted tree has no designated root.
Explanation
Rooted trees are used in hierarchical data like file systems or decision trees.
- 6
What is a directed acyclic graph (DAG) and why are they important?
Model answer
A DAG is a directed graph with no cycles. They are common in dependency structures like build systems or class prerequisites.
Explanation
DAGs enable efficient algorithms for topological ordering and shortest paths.
- 7
Define a bipartite graph and give two equivalent characterizations.
Model answer
A bipartite graph is one whose vertices can be split into two independent sets U and V such that every edge connects a vertex in U to one in V. Equivalently, it is 2-colorable and has no odd-length cycles.
Explanation
Bipartite graphs model relationships between two distinct groups, e.g., jobs and applicants.
- 8
What is a complete graph, and how is it denoted?
Model answer
A complete graph has a unique edge between every pair of vertices. A complete graph with n vertices is denoted Kn.
Explanation
Complete graphs are the densest possible and serve as worst-case graphs for algorithm testing.
- 9
Describe the adjacency matrix representation of a graph. What are its advantages and disadvantages?
Model answer
An adjacency matrix is a 2D array where cell M[i][j] stores the edge weight from node i to node j. Advantages: space-efficient for dense graphs, constant-time edge lookup, simple. Disadvantages: requires O(V2) space, O(V2) time to iterate all edges, poor for sparse graphs.
Explanation
Adjacency matrices are best when the graph is dense (many edges) and quick edge access is needed.
- 10
Explain the adjacency list representation and its trade-offs.
Model answer
An adjacency list is a map from each node to a list of its outgoing edges (neighbor and weight). Advantages: space-efficient for sparse graphs, fast iteration over all edges. Disadvantages: slower edge lookup (O(E)), less efficient for dense graphs.
Explanation
Adjacency lists are the default for most graph algorithms due to their flexibility and efficiency on sparse graphs.
- 11
What is an edge list representation? When is it used?
Model answer
An edge list is an unordered list of all edges, typically stored as triples (u, v, w). Advantages: simple, good for sparse graphs, easy to iterate. Disadvantages: slow edge lookup, memory issues on large graphs. It is seldom used.
Explanation
Edge lists are straightforward but lack structure; they are useful for algorithms that process all edges, like Bellman-Ford.
- 12
How can you convert a grid to an adjacency list or adjacency matrix?
Model answer
Label each cell with numbers 0 to R×C−1, then for each cell add edges to its orthogonal neighbors (up, down, left, right) in the adjacency list or matrix.
Explanation
Grids are implicit graphs; converting them explicitly allows standard graph algorithms to be applied.
- 13
What is the time complexity of a depth-first search on a graph with V vertices and E edges?
Model answer
The time complexity is O(V+E).
Explanation
DFS visits each vertex and edge once, so the complexity is linear in the size of the graph.
- 14
How does DFS differ from BFS in terms of traversal order?
Model answer
DFS plunges depth-first, going as far as possible along each branch before backtracking, while BFS explores nodes in layers, visiting all neighbors of a node before moving to the next level.
Explanation
DFS uses a stack (recursion), BFS uses a queue. BFS finds shortest paths in unweighted graphs; DFS is useful for detecting cycles, connectivity, etc.
- 15
Describe how to find connected components in an undirected graph using DFS.
Model answer
Run DFS from every unvisited node, incrementing a component counter each time a new DFS starts, and assign all nodes visited in that DFS the same component ID.
Explanation
DFS labels each connected component with a unique ID, enabling component counting and identification.
- 16
What problem does BFS solve particularly well?
Model answer
BFS finds the shortest path (in number of edges) on an unweighted graph.
Explanation
BFS explores in increasing distance from the source, guaranteeing that the first time a node is reached is via the shortest path.
- 17
Explain how to use direction vectors to traverse a grid in BFS/DFS.
Model answer
Define direction arrays for row and column offsets (e.g., dr = {-1, 1, 0, 0}, dc = {0, 0, -1, 1}), then iterate over directions, adding offsets to current position, and check bounds and obstacles.
Explanation
Direction vectors simplify grid neighbor computation and easily extend to higher dimensions.
- 18
What is a topological ordering of a directed acyclic graph?
Model answer
A topological ordering is a linear ordering of nodes such that for every directed edge from node A to node B, A appears before B in the ordering.
Explanation
Topological order respects dependencies; it is used in scheduling, build systems, and prerequisite planning.
- 19
Which graphs have a topological ordering?
Model answer
Only directed acyclic graphs (DAGs) have valid topological orderings.
Explanation
Any graph with a directed cycle cannot have a topological order because of cyclic dependencies.
- 20
Describe the DFS-based algorithm for topological sort.
Model answer
Perform DFS on each unvisited node. On the callback (after exploring all neighbors), add the current node to the front of the topological ordering (or push onto a stack). The final order is the reverse of the finish order.
Explanation
DFS ensures that when a node is added, all its dependencies (nodes reachable from it) have already been added, satisfying the topological property.
- 21
How can you find the shortest path in a DAG efficiently?
Model answer
First obtain a topological ordering, then process nodes in that order, relaxing each outgoing edge (updating distance if a shorter path is found). This runs in O(V+E) and handles negative edge weights.
Explanation
Because edges only go forward in topological order, each edge is relaxed exactly once, yielding the shortest path.
- 22
How can you find the longest path in a DAG?
Model answer
Multiply all edge weights by -1, find the shortest path using the DAG algorithm, then multiply the result by -1.
Explanation
Negating edges transforms the longest path problem into a shortest path problem on a DAG, solvable in linear time.
- 23
What is the main constraint for running Dijkstra's algorithm?
Model answer
All edge weights must be non-negative.
Explanation
Negative weights can cause Dijkstra to make incorrect greedy choices; once a node is visited, its distance is assumed optimal, but a negative edge could later improve it.
- 24
What is the time complexity of the lazy implementation of Dijkstra using a binary heap?
Model answer
O(ElogV), assuming each edge relaxation inserts a new key-value pair into the priority queue.
Explanation
Each of the E edges may be relaxed, and each heap operation (insert or extract-min) is O(logV).
- 25
How can you stop Dijkstra early if you only need the shortest path to a specific destination?
Model answer
Once the destination node is visited (popped from the priority queue), its distance is optimal, so the algorithm can terminate.
Explanation
Dijkstra processes nodes in order of increasing distance; when the destination is popped, no shorter path can exist.
- 26
What is the Bellman-Ford algorithm used for that Dijkstra cannot handle?
Model answer
Bellman-Ford can handle graphs with negative edge weights and can detect negative cycles.
Explanation
Bellman-Ford relaxes all edges V−1 times, allowing it to propagate negative weights correctly. A second pass detects negative cycles.
- 27
Explain the steps of the Bellman-Ford algorithm for finding shortest paths.
Model answer
Initialize distance to source as 0, others as infinity. Repeat V−1 times: for each edge (u, v, w), if dist[u] + w < dist[v], update dist[v]. After V−1 iterations, distances are optimal if no negative cycles.
Explanation
Each iteration relaxes all edges; after V−1 iterations, the longest possible path (without cycles) has been considered.
- 28
How does Bellman-Ford detect negative cycles?
Model answer
After V−1 relaxation rounds, run one more round. If any edge can still be relaxed, then a negative cycle exists, and the affected nodes get distance −infinity.
Explanation
If distances still improve after V−1 iterations, a negative cycle must be present because a path can keep getting cheaper.
- 29
What is the Floyd-Warshall algorithm used for?
Model answer
It finds the shortest paths between all pairs of nodes in a graph, and can also detect negative cycles.
Explanation
Floyd-Warshall is an all-pairs shortest path algorithm with O(V3) time, suitable for small to medium graphs.
- 30
How does Floyd-Warshall use dynamic programming?
Model answer
It considers each node k as an intermediate point, updating the shortest path between i and j as min(current, dist[i][k] + dist[k][j]). It builds up solutions for k=0..V-1.
Explanation
The algorithm iteratively improves path distances by allowing more intermediate nodes, reusing previous results.
- 31
What is a bridge in an undirected graph?
Model answer
A bridge is an edge whose removal increases the number of connected components in the graph.
Explanation
Bridges are critical edges; their removal disconnects the graph. They represent vulnerabilities or bottlenecks.
- 32
What is an articulation point (cut vertex)?
Model answer
An articulation point is a node whose removal increases the number of connected components in the graph.
Explanation
Like bridges, articulation points are weak points; their removal splits the graph into more components.
- 33
Describe the low-link value used in finding bridges and articulation points.
Model answer
The low-link value of a node is the smallest node ID reachable from that node during a DFS, including itself.
Explanation
Low-link values propagate through back edges; a bridge is detected when the ID of the node the edge comes from is less than the low-link of the node it goes to.
- 34
What are strongly connected components (SCCs) in a directed graph?
Model answer
Strongly connected components are maximal sets of vertices where every vertex can reach every other vertex in the set via directed paths.
Explanation
SCCs form cycles; Tarjan's algorithm finds them efficiently using DFS and a stack.
- 35
What is Tarjan's algorithm for finding SCCs?
Model answer
It performs DFS, assigning each node an ID and low-link value. Nodes are pushed onto a stack. When a node's ID equals its low-link after exploring all neighbors, all nodes on the stack up to that node form an SCC and are popped.
Explanation
Tarjan's algorithm uses low-link values and a stack invariant to handle arbitrary DFS traversal order.
- 36
Define an Eulerian path and an Eulerian circuit.
Model answer
An Eulerian path is a path that visits every edge exactly once. An Eulerian circuit is an Eulerian path that starts and ends on the same vertex.
Explanation
Eulerian paths are also called Eulerian trails; they are important for problems like route planning or the seven bridges of Königsberg.
- 37
What are the conditions for an undirected graph to have an Eulerian circuit?
Model answer
All vertices must have even degree, and all vertices with non-zero degree must be in a single connected component.
Explanation
If all degrees are even, the graph has an Eulerian circuit (cycle). If exactly two vertices have odd degree, there is an Eulerian path starting and ending at those vertices.
- 38
What are the conditions for a directed graph to have an Eulerian circuit?
Model answer
Every vertex must have equal in-degree and out-degree, and all vertices with non-zero degree must be in a single strongly connected component (or the graph is weakly connected).
Explanation
The balanced in/out degree ensures that you can enter and leave each vertex the same number of times.
- 39
Describe the algorithm to find an Eulerian path in a directed graph.
Model answer
First verify existence (at most one node has out-in=1, at most one has in-out=1, and all others equal). Find start node (the one with out-in=1, or any with outgoing edges). Then perform a depth-first search, removing edges as they are used, and add nodes to the path in reverse order when stuck.
Explanation
The DFS with edge removal ensures all edges are traversed; the algorithm is based on Hierholzer's algorithm.
- 40
What is the Traveling Salesman Problem (TSP)?
Model answer
Given a list of cities and distances between each pair, find the shortest possible route that visits each city exactly once and returns to the origin city (a Hamiltonian cycle of minimum cost).
Explanation
TSP is NP-hard, with significant practical applications in logistics and circuit design.
- 41
How does dynamic programming solve TSP? What is the time complexity?
Model answer
The DP algorithm uses a memo table with state (set of visited nodes, last node) and iterates over subsets of increasing size. Time complexity is O(n2⋅2n).
Explanation
The DP reduces the brute-force O(n!) to O(n22n), making it feasible for n up to about 20-25.
- 42
What is a minimum spanning tree (MST)?
Model answer
A minimum spanning tree is a subset of edges in a weighted graph that connects all vertices together without cycles and with the minimum possible total edge weight.
Explanation
MSTs are used in network design, clustering, and as a basis for approximation algorithms.
- 43
Describe Prim's algorithm for finding an MST.
Model answer
Start from any node, add its cheapest edge to an unvisited node to the tree, and repeat: always add the cheapest edge that connects a visited node to an unvisited node. Use a priority queue (lazy) or an indexed priority queue (eager) for efficiency.
Explanation
Prim's is a greedy algorithm that grows the MST one node at a time, similar to Dijkstra but for MST.
- 44
What is the time complexity of the lazy implementation of Prim's algorithm?
Model answer
O(ElogE), which is equivalent to O(ElogV) since E≤V2.
Explanation
Lazy Prim's inserts all edges into a binary heap; each insertion and extraction is O(logE).
- 45
What is the capacity scaling heuristic for max flow?
Model answer
Capacity scaling prioritizes edges with large remaining capacity first. It uses a parameter Δ (largest power of two ≤ largest capacity) and only considers edges with remaining capacity ≥ Δ. After no more augmenting paths exist, Δ is halved and repeated until Δ=0.
Explanation
This heuristic avoids small bottleneck values early, improving runtime, especially with DFS.
- 46
What is the time complexity of the Edmonds-Karp algorithm?
Model answer
O(V⋅E2).
Explanation
Edmonds-Karp uses BFS to find the shortest augmenting path, guaranteeing O(VE) iterations, each BFS taking O(E) time.
- 47
What is a residual graph and why is it important in max flow algorithms?
Model answer
The residual graph includes both forward edges (with remaining capacity) and backward (residual) edges (with flow capacity). It allows the algorithm to undo previous flow assignments and find better augmenting paths.
Explanation
Residual edges are essential for Ford-Fulkerson method to correctly find the maximum flow by allowing flow to be "reversed" to improve overall flow.
- 48
Explain the level graph in Dinic's algorithm.
Model answer
A level graph is built via BFS from the source, assigning levels (distances). Only edges that go from level L to L+1 with positive remaining capacity are included. It guides augmenting paths toward the sink.
Explanation
The level graph prunes edges that do not make progress toward the sink, reducing the search space.
- 49
What is a blocking flow in Dinic's algorithm?
Model answer
A blocking flow is a situation in the level graph where no more augmenting paths from source to sink can be found because all paths have at least one saturated edge.
Explanation
Dinic's algorithm repeatedly finds blocking flows using DFS; after a blocking flow, the level graph is rebuilt.
- 50
What is the overall time complexity of Dinic's algorithm?
Model answer
O(min(V2/3,E)⋅E) on unit capacity networks, and O(V2E) in general. For bipartite matching, it is O(VE).
Explanation
Dinic's is strongly polynomial and very efficient in practice, especially on bipartite graphs.
- 51
Describe the Ford-Fulkerson method for max flow.
Model answer
Repeatedly find an augmenting path from source to sink in the residual graph with positive remaining capacity. Augment flow along that path by the bottleneck (minimum remaining capacity). Continue until no augmenting path exists.
Explanation
Ford-Fulkerson is a general method; its complexity depends on how augmenting paths are found (e.g., DFS, BFS).
- 52
How can you model unweighted bipartite matching as a max flow problem?
Model answer
Create a source connected to each left-side node with capacity 1, each left node connected to compatible right nodes with capacity 1, and right nodes to sink with capacity 1. The max flow equals the size of the maximum matching.
Explanation
The flow constraints ensure each left node is matched at most once and each right node is matched at most once.
- 53
What is the Mice and Owls problem and how is it solved via max flow?
Model answer
It asks for the maximum number of mice that can reach holes safely before an owl catches them. Model as bipartite flow: source to mice (capacity 1), mice to holes they can reach within radius (capacity 1), holes to sink (capacity equal to hole capacity). Max flow gives answer.
Explanation
The problem is a classic application of network flow to match mice to holes with capacity constraints.
- 54
Explain the concept of an augmenting path in the context of max flow.
Model answer
An augmenting path is a path from source to sink in the residual graph where every edge has strictly positive remaining capacity. The bottleneck value is the minimum remaining capacity along that path.
Explanation
Augmenting the flow by the bottleneck increases the total flow until no more paths exist, at which point flow is maximum.
- 55
What is the significance of the min-cut in relation to max flow?
Model answer
The max-flow min-cut theorem states that the value of the maximum flow equals the capacity of the minimum cut (a partition separating source and sink with minimum total capacity).
Explanation
This theorem provides a dual perspective and is used for analyzing network reliability and bottlenecks.
- 56
How do you find the shortest path on an unweighted graph using BFS?
Model answer
Run BFS from the source, maintaining a queue and a visited array. When the destination is first reached, the number of steps (or the path) can be reconstructed using a predecessor array.
Explanation
BFS explores nodes in order of increasing distance, so the first time the destination is discovered is via the shortest path.

Ask anything
We've read this whole study set, so questions about it get the best answers.