Amazon Interview Question
SDE-3sCountry: United States
1. Select a control/master server. Probably the one with the least IP addr. Standard protocol, not a big deal.[something similar to the spaning tree protocol would do]
2. Control/master server selects a pivot from its own array and broadcasts the value to the est
3. Each slave server partitions its own array based on this pivot value and sends the left , central and right count to the master server.
4. Based on the total number of elements in each slave server and those that the master itself has, master selects one of the left, or right partitions to work on . Each of the slave servers will now be working on this partition.
5. if total_left_count>=n/2: work on left partitions;repeat 2 to 4
else If total_left_count+total_central_count<=n/2: pivot is the median;
Else work on right partition; repeat 2 to 4
Server Set = {s1, s2, ... sn}
Data almost evenly distributed
Take a random number r1 from any server and broadcast to all the servers.
Each server partition their dataset into two parts
where => partition 1 > r1 and parition 2 < r1
For each set get the size of partition1 and partition2
S1=> p11 and p12
S1=> p21 and p22
.
.
Sn=> pn1 and pn2
Location of mediam = sum (P11,P12...pn1,pn2)/2 = k
if sum(pi1) < k then k k - sum(pi1)-k
1. Select a control/master server. Probably the one with the least IP addr. Standard protocol, not a big deal.[something similar to the spaning tree protocol would do]
- nitsal August 15, 20192. Control/master server selects a pivot from its own array and broadcasts the value to the est
3. Each slave server partitions its own array based on this pivot value and sends the left , central and right count to the master server.
4. Based on the total number of elements in each slave server and those that the master itself has, master selects one of the left, or right partitions to work on . Each of the slave servers will now be working on this partition.
5. if total_left_count>=n/2: work on left partitions;repeat 2 to 4
else If total_left_count+total_central_count<=n/2: pivot is the median;
Else work on right partition; repeat 2 to 4