KatInterview

Distributed Tree Traversal and Reliable Neighbor Messaging Protocol

Trees & GraphsModel answer
MediumModel answerTrees & Graphstrees-graphsdistributed-systemsmessage-passing

Last updated

Design a reliable message passing protocol across adjacent tree nodes, then compute total network size and discover paths under network faults.

You are building an algorithm for a distributed network of nodes arranged in a graph structure. Initially, assume the network forms a rooted tree, where every node only knows the identifier of its parent and its children, and can only communicate directly with these immediate neighbors.

Your task is to design and implement a protocol that answers the following requirements:

  1. Reliable Neighbor Link Layer (sendMessage): Implement a reliable messaging interface between adjacent nodes over an asynchronous, lossy link layer that may drop, duplicate, or reorder packets.

  2. Network Node Counter: Using only asynchronous neighbor-to-neighbor message passing, calculate the total number of nodes in the entire network. State all assumptions, and analyze the message and time complexity. Explain how to generalize this step if the topology is an arbitrary connected graph rather than a tree.

  3. Path Routing Discovery: Design protocols to compute and return:

    • (a) The sequential path of node IDs from any starting node $u$ up to the root.
    • (b) The sequential path of node IDs between two arbitrary nodes $u$ and $v$.
  4. Fault Tolerance & Edge Handling: Explain how your protocol handles message loss, duplicate delivery, packet reordering, and node timeouts. Discuss how termination detection is guaranteed.

Hints

Hint 1

Think about standard networking protocols: how do sequence numbers and ACKs solve packet loss, duplicates, and reordering across a single hop?

Hint 2

To count nodes in a tree, combine top-down broadcast with bottom-up aggregation (convergecast). Every leaf node can easily report its subtree count as 1.

Hint 3

For routing between arbitrary nodes u and v in a tree, think about how finding each node's path to the root lets you determine their Lowest Common Ancestor (LCA).