liveBook · Manning

Edge

As explained in Fabulous Adventures in Data Structures and Algorithms

An edge is a graph or tree connection from one node to another that may carry a label.

An edge is a labeled connection from one node to another. In a trie, each outgoing edge carries a character label and points to the node reached by that character. section 5.2.1

A trie node exposes edges through operations that preserve their meaning:

  • EdgeLabels lists the labels on outgoing edges. section 5.2.1
  • FollowEdge returns the node reached by a label; TryFollowEdge avoids failure when the edge is absent. section 5.2.1
  • HasEdge tests existence, while AddNewNode and TryAddNewNode create or reuse an outgoing edge. section 5.2.1
Listing 5.2 A trie node
sealed class Node
{
    private readonly Dictionary<char, Node> edges = [];
    public bool IsEnd { get; set; }
    public IEnumerable<char> EdgeLabels => edges.Keys;
    public Node FollowEdge(char c) => edges [c]; #1
    public Node? TryFollowEdge(char c) =>  #2
        HasEdge(c) ? FollowEdge(c) : null;
    public bool HasEdge(char c) => edges.ContainsKey(c);
    public Node AddNewNode(char c) => edges [c] = new();
    public Node TryAddNewNode(char c) => 
        HasEdge(c) ? FollowEdge(c) : AddNewNode(c);
}

A compact C# trie-node implementation represents labeled edges with Dictionary<char, Node> while hiding that storage behind node operations. section 5.2.1

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines labels, targets, traversal, lookup, and creation, but does not develop general graph algorithms.
Examples
Uses a C# trie node whose Dictionary<char, Node> stores outgoing character-labeled edges.
What you can do after
Apply edge accessors to traverse, inspect, and extend a mutable trie node.
How it connects
Connects nodes with tries, word endings, mutable data structures, and directed left-to-right traversal.

Also explained in

Compare how 18 books explain edge →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.