Consider an anonymous ring of size n. Each node v stores an input boolean value
ID: 441238 • Letter: C
Question
Consider an anonymous ring of size n. Each node v stores an input boolean value i(v). When the algorithm terminates, then every node is to store the output in its private variable. Every node knows n, in that n can be a part of code. (a) Give a deterministic algorithm to compute the global Boolean OR of all input values on the ring. (b) Show that any such algorithm requires (n2) messages. Hint: There is no need to be formal, just give convincing intuitions. Observe that if there is a leader in the network then O(n) messages can sufficeExplanation / Answer
Algorithm: depth(root) "Return the how deep the tree is." Input: root of binarytreeoutput: depth of binarytree STEP1: if not root.left is Nonethen leftdepth = root.left.depth() 2: leftdepth = 0 3: if not root.right is Nonethen rightdepth = root.right.depth() else: rightdepth = 0 end if 4: return max(leftdepth, rightdepth) + 1 5:End depth