Docsity

Reducing Complexity in Distributed Algorithms: DFS, Leader Election, Unidirectional Ring, Assignments of Algorithms and Programming

Toggle sidebar
bg1
Jeffrey Hellrung
Wednesday, April 11, 2007
Com Sci 280D, HW 1
1. Message complexity of a distributed algorithm is the number of messages per link spent (worst case)
until the algorithm reaches quiescence. The time complexity is the longest time an execution can last
if every message has to be delivered within a unit of time from the time it was sent (but this does not
mean that teh system is synchronous since some messages may be delivered in a small fraction of a
unit of time and some may be delivered after a full unit). DFS, as is, is almost a distributed algorithm,
so its message complexity is O(E), as well as its time complexity. Amend DFS for the distributed
setting so that there is some concurrency in its operation that reduces this time complexity to O(n).
It is nevertheless DFS as it produces a DFS tree (recall that not every tree is a DFS tree).
Solution
DFS works as before, except that each node keeps a set of possible children, originally initialized to
all its neighbors. Once DFS explores to a node i, a message is sent to each neighbor jin i’s set of
possible children to remove ifrom j’s set of possible children. DFS then explores, sequentially, the
subtrees down each of i’s possible children (the exploration of one subtree may, in fact, further reduce
the set of possible children of i). In this way, the invariant is always kept that a node’s set of possible
children corresponds to its neighbors who are not yet part of the DFS tree. Since each message sent
across a link not in the DFS tree is sent simultaneously with a message sent across a link which is part
of the DFS tree, the time complexity must be the number of messages sent across links in the DFS
tree, which is clearly O(n).
1
pf3
pf4

Partial preview of the text

Download Reducing Complexity in Distributed Algorithms: DFS, Leader Election, Unidirectional Ring and more Assignments Algorithms and Programming in PDF only on Docsity!

Wednesday, April 11, 2007 Com Sci 280D, HW 1

  1. Message complexity of a distributed algorithm is the number of messages per link spent (worst case) until the algorithm reaches quiescence. The time complexity is the longest time an execution can last if every message has to be delivered within a unit of time from the time it was sent (but this does not mean that teh system is synchronous since some messages may be delivered in a small fraction of a unit of time and some may be delivered after a full unit). DFS, as is, is almost a distributed algorithm, so its message complexity is O(E), as well as its time complexity. Amend DFS for the distributed setting so that there is some concurrency in its operation that reduces this time complexity to O(n). It is nevertheless DFS as it produces a DFS tree (recall that not every tree is a DFS tree). Solution DFS works as before, except that each node keeps a set of possible children, originally initialized to all its neighbors. Once DFS explores to a node i, a message is sent to each neighbor j in i’s set of possible children to remove i from j’s set of possible children. DFS then explores, sequentially, the subtrees down each of i’s possible children (the exploration of one subtree may, in fact, further reduce the set of possible children of i). In this way, the invariant is always kept that a node’s set of possible children corresponds to its neighbors who are not yet part of the DFS tree. Since each message sent across a link not in the DFS tree is sent simultaneously with a message sent across a link which is part of the DFS tree, the time complexity must be the number of messages sent across links in the DFS tree, which is clearly O(n).

Wednesday, April 11, 2007 Com Sci 280D, HW 1

  1. To elect a leader each node is going to spawn its independent version of DFS and versions will kill versions such that only one succeeds to propagate throughout the whole net. Design such a “kill mechanism” so that the total message complexity is O(E + n log n). Solution It seems like if each node could count how many nodes it knew of were in the DFS tree associated with that node, then an efficient kill mechanism would be to kill the active DFS node from one root node when it tries to connect a node associated with the DFS tree of another root node that is known that this other DFS tree is at least as large, perhaps breaking ties by going with the higher ID. I can’t yet get this precise, though.

Wednesday, April 11, 2007 Com Sci 280D, HW 1

  1. In a unidirectional ring of finite automata, one node is woken up. Design an efficient (O(n log n)) bit complexity algorithm so that the node behind the starter will identify itself as such (a finite automaton means that the memory of hte processor produced in the factory is any constant of your choice but not a function of the size of the ring in which it will be put. Thus, for instance, this precludes IDs). Solution Denote the node behind the start node as the last node. To get the O(n log n) total message complexity, in each round, we’d like to eliminate half of the nodes which consider themselves as candidates for the last node. Denote a node considering itself as a candidate for the last node as an active node; an invariant of the algorithm is that the last node will always be active. The idea is to, starting with the start node, alternate passing 0 and 1 between the active nodes (where inactive nodes act simply as repeaters) around the ring until the start node receives a 0 or a 1. The reception of a 0 at the start node means the last node sent a 0, hence we can safely inactivate all nodes which passed a 1 (which is about half of the active nodes). Similarly, if the start node receives a 1, we can safely inactivate all nodes which passed a 0. Repeating this procedure will clearly reduce the number of active nodes to 1 in O(n log n) total messages; however, we need a mechanism by which to determine that only 1 active node remains and to signal the last node in such a case. Thus, after a round of inactivating nodes, the start node will query the ring to determine if only 1 active node remains (which necessarily must be the last node, by the invariant), and if so, signal the last node (i.e., all active nodes) to identify itself as the last node. Otherwise, the start node will initiate another alternating 0/1 message. To be more specific, each non-start node will have one of 4 states: Active, W aiting; Active, Sent(0); Active, Sent(1); or Inactive. The initial state of each non-start node will be Active, W aiting. A node in the Inactive state sends a message if and only if it receives a message, and it sends precisely the same message it receives to its next node. In the beginning of each “round”, the start node initiates a ring of messages by sending 0 to its next node. A node in the Active, W aiting state, upon reception of a message consisting of b ∈ { 0 , 1 }, changes its state to Active, Sent(¬b) and sends ¬b to its next node. Once the ring of messages returns to the start node, the start node will receive b ∈ { 0 , 1 } from the last node. The start node then sends an Inactivate(¬b) message to its next node. A node in the Active, Sent(b) state will change its state to Active, W aiting and repeat this message to its next node; a node in the Active, Sent(¬b) state will change its state to Inactive and repeat the message to its next node. Once the inactivate message returns to the start node, the start node then sends a query message to its next node: “How many active nodes remain? So far 0.” The first active node receiving this message will increase the count to 1, thus relaying the message “How many active nodes remain? So far 1.”. The second and subsequent active nodes will denote the count as “more than 1”, relaying “How many active nodes remain? More than 1.”. should the start node receive a response of “more than 1”, it will initiate another round of alternating 0/1 messages to further reduce the number of active nodes. Once the start node receives a response indicating only 1 remaining active node, it can then signal the last node to identify itself as the last node: “The active node is the last node.”