Problem Statement: A Research team wants to establish a research center in a region where they found some rare-elements.They want to make it closest to all the rare-elements as close as possible so that they can reduce overall cost of research over there.It is given that all the rare-element’s location is connected by roads.It is also given that Research Center can only be build on road.Team decided to assign this task to a coder.If you feel you have that much potential. Here is the Task :- Find the shortest of the longest distance of research center from given locations of rare-elements. Locations are given in the matrix cell form where 1 represents roads and 0 no road.. number of rare-element and their location was also given(number<=5) and order of square matrix was less than equal to 20
My approach to solve the problem is to start BFS(Breadth First Search) from one of the rare-element location(say X) and replace the value of the road(marked as 1) by the shortest value to reach the cell from that location X. Similarly, start BFS from all the other locations and add the shortest value to the existing cell value. Once BFS is complete for all the locations, scan the matrix for the minimum value.
Will the above approach work? Is there an algorithm specifically meant for such problems?