A node stores local state and connects to related nodes through labeled edges. In a trie, that state is whether a word ends here; outgoing edges map characters to successor nodes. Traversal proceeds from root to leaves, so parent references are unnecessary. section 5.2.1
A mutable node can expose operations such as checking an edge, following it, listing labels, and adding a successor. Keeping the dictionary private preserves the node-and-edge vocabulary and leaves the representation replaceable. 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# implementation makes the node’s state, edge lookup, safe traversal, and incremental construction explicit. section 5.2.1


















