Bloomberg | Onsite | Consensus on the largest integer in the network
Anonymous User
3404

Imagine we have a network of nodes where new information can be passed from one node to another node anaglous to how new gossip spreads from one person to the next. In order for information to spread across the network, each node finds a node to pass down the latest info or gossip it knows and this process repeats til the information is consistent across all nodes. This gossiping communication is one way a distributed system can reach consensus on information the network holds without seeing all the data available from all the nodes.
Let's say we have a list of nodes each holding a unique positive integer and we'd like to use this method to reach a consensus on what the largest integer is. A node can look like the following,

struct Node
{
  int my_value;
  int largest_value_i_know;
  
  Node(int value)
  {
    my_value = value;
    largest_value_i_know = value; //self, that's the only thing  it knows 
  };
};

We will use a vector of nodes to represent the network and the goal is to implement a function like this:

void find_largest_value(vector<Node>& nodes) //prints out the consensus and number of rounds.

Assumptions/ Hints by interviewer:
You're given random neighbor assignments, 3 neighbors per node.
You're given the assumption that this graph is fully connected.
No messages are lost.

Note:
1.How will you represent a single node? //Define class and data structure and write methods.
2.How will you write data to ther nodes's buffer for propogation. //One way could be each node will have its own arraylist as a buffer. This arraylist is exposed to other nodes via a public method to append a value.

Comments (10)