Question: IN JAVA!!! Throughout this coursework, the network on which our algorithms are to be executed is a bidirectional ring, as depicted in Figure 1. ui
IN JAVA!!!


Throughout this coursework, the network on which our algorithms are to be executed is a bidirectional ring, as depicted in Figure 1. ui Un 112 Un-1 us us 14 U7 us t16 Figure 1: A bidirectional ring network on n processors. In our setting, all processors execute the same algorithm, do not know the number n of processors in the system in advance, but they do know the structure of the network and are equipped with unique ids. The ids are not necessarily consecutive and for simplicity you can assume that they are chosen from {1, 2, ..., an}, where a > 1 is a small constant (e.g., for a = 3, the n processors will be every time assigned unique ids from {1, 2, ..., 3n 1, 3n}). Additionally, every processor can distinguish its clockwise from its counterclockwise neighbour, so that, for example, it can choose to send to only one of them or to send a different message to each of them. Processors execute in synchronous rounds, as in every example we have discussed so far in class. 3.1 Implementing the LCR Algorithm30% of the assignment mark As a first step, you are required to implement the LCR algorithm for leader election in a ring. The pseudocode of the non-terminating version of LCR can be found in the lecture notes and is also given here for convenience (Algorithm 1). Algorithm 1 LCR (non-terminating version) Code for processor ui, i {1,2,...,n}: Initially: u; knows its own unique id stored in myID; sendID; := myID; status, := "unknown" 6: 1: if round = 1 then 2: send (sendI D) to clockwise neighbour 3: else// round > 1 upon receiving (inID) from counterclockwise neighbour 5: if inID > myID; then sendID; := inID 7: send (sendID;) to clockwise neighbour 8: else if inID= myID; then 9: status; := "leader 10: else if inID
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
