5. Walk, Trail, Path, Cycle

Introduction

  • Walk: A walk is a sequence of vertices and edges in a graph. Walks can repeat vertices and edges, and there's no requirement for it to start and end at the same vertex. An example might be 0-1-3-5-2-3-1 in a graph.
  • Trail: A trail is a walk in which no edges are repeated, but vertices can be. This means that while the walk may go through the same vertex more than once, it will not use the same edge more than once. An example might be 3-5-2-3-4 in a graph where no edges are repeated.
  • Path: A path is a trail in which neither vertices nor edges are repeated. It's a sequence of vertices and edges where all are distinct. This is often what people are referring to when they talk about the "shortest path" between two vertices in a graph. An example might be 2-3-4-6 in a graph.
  • Cycle: A cycle is a walk where the first vertex is the same as the last, and no other vertices or edges are repeated. Essentially, it is a path that starts and ends on the same vertex, forming a loop. An example might be 3-4-6-5-3 in a graph, assuming the vertices and edges are not repeated elsewhere in the cycle.

Exercise

Click on a vertex to start a walk, then click its neighbors to continue the walk. Click on current vertex again to remove the walk.

You can't remove a vertex or edge if it is part of a walk.

  1. 1.

    Try to create a walk with 5 vertices.

  2. 2.

    Try to create a walk that it is also a trail but not a path.

  3. 3.

    Try to create a path with 7 vertices.

  4. 4.

    Try to create a cycle with 7 vertices.

  • Walk: Empty
  • isWalk: false
  • isTrail: false
  • isPath: false
  • isCycle: false
0123456