Graph and Tree Models

  1. Reading Vertices and Edges in a Graph

    A graph names a set of vertices and a set or collection of edges connecting pairs of vertices.

    Undergraduate
  2. Directed and Undirected Connections

    A directed edge describes a permitted move in one direction. An undirected edge relates its endpoints in both directions.

    Undergraduate
  3. Parallel Edges and Self-Loops

    Some graph models permit more than one edge between a pair of vertices and edges whose two ends coincide.

    Undergraduate
  4. Counting the Degree of a Vertex

    Degree counts incident edge ends. A directed graph distinguishes incoming from outgoing edges.

    Undergraduate
  5. Walks, Paths, and Repeated Vertices

    A walk follows consecutive edges and can return to a vertex. A simple path visits each vertex at most once.

    Undergraduate
  6. Testing Reachability from One Vertex

    A vertex is reachable when a sequence of permitted edges leads to it from the source, including the trivial route to the source itself.

    Undergraduate
  7. Connected Components by Hand

    A connected component of an undirected graph contains all vertices reachable from one another. Components form a partition of the vertex set.

    Undergraduate
  8. Mutual Reachability in a Directed Graph

    Strong connectivity requires that each vertex in a component can reach each other through directed edges.

    Undergraduate
  9. A Breadth-First Search by Hand

    Breadth-first search expands the earliest waiting vertex and discovers reachable vertices in layers by unweighted distance.

    Undergraduate
  10. A Depth-First Search by Hand

    Depth-first search follows one path as far as it can before returning to explore unfinished alternatives.

    Undergraduate
  11. Measuring Shortest Routes by Edge Count

    In a graph where each permitted step has equal cost, a shortest route minimizes the number of edges traversed.

    Undergraduate
  12. Adding Edge Weights Along a Route

    A weighted path's additive cost is the sum of the weights of its edges. The best route can have more edges than an alternative.

    Undergraduate
  13. Recovering a Path from Predecessors

    A search can store one predecessor per discovered vertex and reconstruct a path only for a requested target.

    Undergraduate
  14. A Tree as a Connected Acyclic Graph

    An undirected tree is connected and contains no cycles. There is exactly one simple path between each distinct pair of vertices.

    Undergraduate
  15. Parents, Children, and Depth in Rooted Trees

    Rooting a tree gives each nonroot vertex one parent on its path to the root. Depth is its distance in edges from that root.

    Undergraduate
  16. Finding the Lowest Common Ancestor by Hand

    For two vertices in a rooted tree, their lowest common ancestor is the deepest vertex belonging to both parent chains.

    Undergraduate
  17. Building a Spanning Tree from Search

    A search in a connected graph can record one discovery edge for each vertex except the source, forming a spanning tree.

    Undergraduate
  18. Counting Edges in a Forest

    Count edges in a forest by adding the edge counts of its disjoint tree components.

    Undergraduate
  19. A Cycle Witness in an Undirected Graph

    A simple undirected graph has a cycle when some walk returns to its start through distinct edges and otherwise distinct vertices.

    Undergraduate
  20. A Directed Cycle in Prerequisites

    A directed cycle among prerequisite edges makes it impossible to satisfy all of them by placing every prerequisite first.

    Undergraduate
  21. Topological Ordering by Removing Ready Tasks

    In a directed acyclic dependency graph, tasks with no remaining incoming prerequisites can be placed next.

    Undergraduate
  22. Checking a Graph with Two Colors

    A graph is bipartite when vertices can be assigned one of two parts and every edge crosses between the parts.

    Undergraduate
  23. Turning a Grid into a Graph

    A grid search can treat each permitted cell as a vertex and each legal move as a directed or undirected edge.

    Undergraduate
  24. Building Graphs from Input Records

    Input records can describe vertices, connections, and attributes. A validation step resolves which named endpoints exist and which repeats are allowed.

    Undergraduate
  25. Reversing All Edges in a Directed Graph

    The reverse graph keeps the same vertices and reverses the start and end of each directed edge.

    Undergraduate
  26. Counting Edges of a Complete Simple Graph

    A complete simple undirected graph connects every pair of distinct vertices with one edge.

    Undergraduate
  27. Sparse and Dense Graph Representations

    The number of actual edges guides how much work and storage different graph representations need.

    Undergraduate
  28. Measuring Distance from Several Sources

    An unweighted graph can assign each vertex the distance to its nearest source by starting all source vertices in the same zero-distance layer.

    Undergraduate
  29. Taking the Subgraph Induced by a Vertex Set

    An induced subgraph keeps a chosen set of vertices and every original edge with both endpoints in that set.

    Undergraduate
  30. Modeling Task Prerequisites as a Graph

    A prerequisite graph represents allowable execution orders and identifies tasks that may be independent under its stated requirements.

    Undergraduate