🌍 Data Structures & Algorithms · subject

Data Structures & Algorithms Graphs & Advanced Structures Syllabus

The Graphs & Advanced Structures syllabus for Data Structures & Algorithms in full: 6 chapters and 17 topics, every one listed below, plus 56 Graphs & Advanced Structures flashcards with answers.

6Chapters
17Topics
56Flashcards

Graphs & Advanced Structures syllabus: all 6 chapters

Expand any chapter to see its topics and sub-topics.

  1. Graph Representation

    2 topics
    • Graph Types
    • Representations
  2. Graph Traversal

    3 topics
    • Breadth-First Search
    • Depth-First Search
    • Topological Sorting
  3. Shortest Path Algorithms

    4 topics
    • Dijkstra's Algorithm
    • Bellman-Ford Algorithm
    • Floyd-Warshall Algorithm
    • A* Search
  4. Minimum Spanning Trees

    2 topics
    • Kruskal's Algorithm
    • Prim's Algorithm
  5. Disjoint Set Union

    3 topics
    • Union-Find Structure
    • Optimizations
    • Applications
  6. Advanced Graph Topics

    3 topics
    • Strongly Connected Components
    • Articulation Points and Bridges
    • Network Flow Basics

Data Structures & Algorithms Graphs & Advanced Structures flashcards — 56 questions with answers

  1. What distinguishes a directed graph from an undirected graph?

    In a directed graph, each edge $(u,v)$ has an orientation from $u$ to $v$, so adjacency is not symmetric. In an undirected graph, an edge $\{u,v\}$ has no direction and connects both endpoints equally.

  2. Define a weighted graph and give the standard notation for an edge weight.

    A weighted graph assigns a numeric value to each edge, written $w(u,v)$ (or $w(e)$). Weights model costs, distances, or capacities.

  3. What is the maximum number of edges in a simple undirected graph with $n$ vertices, and in a simple directed graph?

    Undirected: $\binom{n}{2} = \frac{n(n-1)}{2}$. Directed (no self-loops): $n(n-1)$.

  4. Define a complete graph $K_n$ and state its edge count.

    A complete graph $K_n$ has an edge between every pair of distinct vertices. It has $\frac{n(n-1)}{2}$ edges.

  5. What is a bipartite graph, and what property characterizes it in terms of cycles?

    A bipartite graph's vertices split into two disjoint sets with all edges going between the sets. A graph is bipartite if and only if it contains no odd-length cycle.

  6. Define a tree in graph terms and give its edge count for $n$ vertices.

    A tree is a connected, acyclic undirected graph. A tree on $n$ vertices has exactly $n-1$ edges.

  7. What is a DAG?

    A Directed Acyclic Graph: a directed graph with no directed cycles. DAGs admit a topological ordering.

  8. When is a graph called dense versus sparse?

    Dense: $|E|$ is close to $|V|^{2}$ (i.e., $|E| = \Theta(V^{2})$). Sparse: $|E|$ is close to $|V|$ (i.e., $|E| = O(V)$).

  9. Compare space complexity of an adjacency matrix versus an adjacency list.

    Adjacency matrix: $O(V^{2})$ space. Adjacency list: $O(V + E)$ space. Lists are preferred for sparse graphs; matrices for dense graphs.

  10. How long does it take to check whether edge $(u,v)$ exists in an adjacency matrix versus an adjacency list?

    Adjacency matrix: $O(1)$. Adjacency list: $O(\deg(u))$ in the worst case.

  11. What is the time to iterate over all neighbors of a vertex $u$ in each representation?

    Adjacency list: $O(\deg(u))$. Adjacency matrix: $O(V)$, since the entire row must be scanned.

  12. State the Handshaking Lemma for undirected graphs.

    The sum of all vertex degrees equals twice the number of edges: $$\sum_{v \in V} \deg(v) = 2|E|.$$

  13. What data structure does BFS use, and what order does it explore vertices?

    BFS uses a FIFO queue and explores vertices in order of increasing distance (level by level) from the source.

  14. State the time and space complexity of BFS on a graph with adjacency lists.

    Time: $O(V + E)$. Space: $O(V)$ for the queue and visited/distance arrays.

  15. What problem does BFS solve optimally, and under what edge-weight condition?

    BFS finds shortest paths (fewest edges) from a source in an unweighted graph, or equivalently when all edge weights are equal.

  16. What data structure underlies DFS, and how can it be implemented?

    DFS uses a LIFO stack, implemented either with explicit recursion (call stack) or an explicit stack.

  17. State the time and space complexity of DFS with adjacency lists.

    Time: $O(V + E)$. Space: $O(V)$ for the recursion stack and visited array.

  18. In DFS, what are tree edges, back edges, forward edges, and cross edges?

    Tree edge: to an unvisited vertex. Back edge: to an ancestor (indicates a cycle). Forward edge: to a descendant already finished. Cross edge: between unrelated subtrees. In undirected DFS only tree and back edges occur.

  19. How does DFS detect a cycle in a directed graph?

    A directed graph has a cycle if and only if DFS encounters a back edge—an edge to a vertex currently on the recursion stack (in the 'gray'/in-progress state).

  20. Define a topological sort of a DAG.

    A linear ordering of vertices such that for every directed edge $(u,v)$, $u$ appears before $v$. It exists if and only if the graph is a DAG.

Show the other 36 Graphs & Advanced Structures flashcards
  1. Describe Kahn's algorithm for topological sorting.

    Repeatedly remove a vertex with in-degree $0$, append it to the order, and decrement the in-degree of its neighbors. Uses a queue of zero-in-degree vertices; runs in $O(V + E)$. If vertices remain with nonzero in-degree, a cycle exists.

  2. How does DFS produce a topological order?

    Run DFS and push each vertex onto a stack when it finishes (post-order). The reversed finish order is a valid topological sort. Runs in $O(V + E)$.

  3. What problem does Dijkstra's algorithm solve, and what is its key edge-weight restriction?

    Single-source shortest paths in a graph with non-negative edge weights. It fails if any edge weight is negative.

  4. State Dijkstra's running time with a binary heap and with a Fibonacci heap.

    Binary heap: $O((V + E)\log V)$. Fibonacci heap: $O(E + V\log V)$.

  5. What is the relaxation step used in shortest-path algorithms?

    For edge $(u,v)$ with weight $w$: if $d[u] + w < d[v]$, set $d[v] = d[u] + w$ and record $u$ as the predecessor of $v$.

  6. Why does Dijkstra's greedy choice work only with non-negative weights?

    Dijkstra finalizes the closest unfinalized vertex assuming no later path can be shorter. A negative edge could reduce an already-finalized distance, violating this invariant.

  7. What problem does the Bellman-Ford algorithm solve, and what can it detect that Dijkstra cannot?

    Single-source shortest paths allowing negative edge weights. It can detect negative-weight cycles reachable from the source.

  8. State the running time of Bellman-Ford and describe its main loop.

    $O(V \cdot E)$. It relaxes all $E$ edges repeatedly for $V-1$ iterations; a further relaxation on the $V$-th pass indicates a negative cycle.

  9. Why are exactly $V-1$ relaxation passes sufficient in Bellman-Ford (absent negative cycles)?

    A shortest path in a graph without negative cycles has at most $V-1$ edges, and each pass extends correct distances by at least one more edge along such paths.

  10. What problem does the Floyd-Warshall algorithm solve, and what is its complexity?

    All-pairs shortest paths, allowing negative edges (but no negative cycles). Time $O(V^{3})$, space $O(V^{2})$.

  11. Write the Floyd-Warshall recurrence for the shortest distance $d_{ij}^{(k)}$.

    $$d_{ij}^{(k)} = \min\left(d_{ij}^{(k-1)},\; d_{ik}^{(k-1)} + d_{kj}^{(k-1)}\right),$$ where $k$ ranges over intermediate vertices.

  12. How does Floyd-Warshall detect a negative cycle?

    After the algorithm, a negative cycle exists if any diagonal entry $d_{ii} < 0$.

  13. What is the A* search algorithm and its evaluation function?

    A* is a best-first shortest-path search using $$f(n) = g(n) + h(n),$$ where $g(n)$ is the known cost from the start and $h(n)$ is a heuristic estimate of the cost to the goal.

  14. What condition on the heuristic $h$ guarantees A* finds an optimal path?

    $h$ must be admissible: it never overestimates the true cost to the goal, i.e., $h(n) \leq h^{*}(n)$. Consistency (monotonicity) is a stronger sufficient condition.

  15. Define a consistent (monotone) heuristic for A*.

    For every edge $(n, n')$ with cost $c$: $$h(n) \leq c(n, n') + h(n').$$ Consistency implies admissibility and guarantees each node is expanded at most once.

  16. How does A* relate to Dijkstra's algorithm?

    A* with the zero heuristic $h(n) = 0$ reduces exactly to Dijkstra's algorithm. A good heuristic focuses the search toward the goal, expanding fewer nodes.

  17. Define a minimum spanning tree (MST).

    A spanning tree (connected, acyclic subgraph including all $V$ vertices) of a weighted undirected graph whose total edge weight is minimum.

  18. Describe Kruskal's algorithm and its complexity.

    Sort all edges by weight ascending; add each edge if it connects two different components (checked via Union-Find), skipping edges that form cycles. Runs in $O(E \log E) = O(E \log V)$.

  19. Describe Prim's algorithm and its complexity with a binary heap.

    Grow the MST from a start vertex, repeatedly adding the minimum-weight edge crossing from the tree to a new vertex, using a priority queue. Time $O(E \log V)$ with a binary heap; $O(E + V\log V)$ with a Fibonacci heap.

  20. State the cut property for MSTs.

    For any cut (partition of vertices), the minimum-weight edge crossing the cut belongs to some MST. This justifies the greedy choices in both Prim's and Kruskal's algorithms.

  21. State the cycle property for MSTs.

    For any cycle, the maximum-weight edge on that cycle is not in any MST (assuming unique weights). Kruskal's algorithm implicitly discards such edges.

  22. What two operations does a Union-Find (Disjoint Set Union) structure support?

    $\text{Find}(x)$: return the representative of $x$'s set. $\text{Union}(x, y)$: merge the sets containing $x$ and $y$.

  23. Name the two optimizations for Union-Find and state the resulting amortized complexity.

    Union by rank/size and path compression. Together they give nearly constant amortized time $O(\alpha(n))$ per operation, where $\alpha$ is the inverse Ackermann function.

  24. How does path compression work in Union-Find?

    During a $\text{Find}$ operation, every node visited on the path to the root is re-pointed directly to the root, flattening the tree for future queries.

  25. How does union by rank/size work?

    When merging two trees, attach the root of the shorter/smaller tree under the root of the taller/larger one, keeping trees shallow and bounding height at $O(\log n)$.

  26. Define a strongly connected component (SCC) of a directed graph.

    A maximal set of vertices such that every vertex is reachable from every other vertex in the set via directed paths.

  27. Name two linear-time algorithms for finding SCCs and their complexity.

    Kosaraju's algorithm (two DFS passes, using the transpose graph) and Tarjan's algorithm (single DFS with low-link values). Both run in $O(V + E)$.

  28. Outline Kosaraju's algorithm for SCCs.

    1) Run DFS on $G$, pushing vertices onto a stack by finish time. 2) Compute the transpose $G^{T}$. 3) Pop vertices in decreasing finish order and run DFS on $G^{T}$; each DFS tree is one SCC.

  29. Define an articulation point (cut vertex) in an undirected graph.

    A vertex whose removal (with its incident edges) increases the number of connected components—i.e., it disconnects part of the graph.

  30. Define a bridge in an undirected graph.

    An edge whose removal increases the number of connected components. Bridges belong to no cycle.

  31. How are articulation points and bridges found efficiently, and what is the key quantity used?

    By a single DFS in $O(V + E)$ using discovery times $\text{disc}[u]$ and low-link values $\text{low}[u]$ (the earliest reachable ancestor). An edge $(u,v)$ is a bridge if $\text{low}[v] > \text{disc}[u]$; a non-root $u$ is an articulation point if some child $v$ has $\text{low}[v] \geq \text{disc}[u]$.

  32. In a flow network, what is a flow and what constraints must it satisfy?

    A flow $f(u,v)$ on edges must satisfy the capacity constraint $0 \leq f(u,v) \leq c(u,v)$ and flow conservation: at every non-source, non-sink vertex, total inflow equals total outflow.

  33. State the Max-Flow Min-Cut Theorem.

    In a flow network, the maximum value of an $s$-$t$ flow equals the minimum capacity of an $s$-$t$ cut: $$\max_{f} |f| = \min_{(S,T)} c(S, T).$$

  34. What is an augmenting path, and which algorithm uses them to compute max flow?

    An augmenting path is a source-to-sink path in the residual graph with spare capacity on every edge. The Ford-Fulkerson method repeatedly augments along such paths until none remain.

  35. What is the Edmonds-Karp algorithm and its time complexity?

    An implementation of Ford-Fulkerson that finds augmenting paths via BFS (shortest augmenting path first). It runs in $O(V E^{2})$.

  36. Compare Dijkstra, Bellman-Ford, and Floyd-Warshall by scope, weight support, and complexity.

    Dijkstra: single-source, non-negative weights, $O((V+E)\log V)$. Bellman-Ford: single-source, allows negative weights (detects negative cycles), $O(VE)$. Floyd-Warshall: all-pairs, allows negative weights, $O(V^{3})$.

Data Structures & Algorithms Graphs & Advanced Structures FAQ

What is in the Data Structures & Algorithms Graphs & Advanced Structures syllabus?

Data Structures & Algorithms Graphs & Advanced Structures is split into 6 chapters: Graph Representation, Graph Traversal, Shortest Path Algorithms, Minimum Spanning Trees, Disjoint Set Union and Advanced Graph Topics. Together they contain 17 topics.

How many chapters are in Data Structures & Algorithms Graphs & Advanced Structures?

6 chapters, containing 17 topics. The largest chapter is Shortest Path Algorithms, with 4 topics.

Are there flashcards for Data Structures & Algorithms Graphs & Advanced Structures?

Yes — a 56-card Graphs & Advanced Structures deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.