Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This problem can be reduced to a problem in graph theory where you find all groups of connected nodes in a graph.</p> <p>An efficient way to solve this problem is doing a "flood fill" algorithm, which is essentially a recursive breath first search. This <a href="http://en.wikipedia.org/wiki/Flood_fill" rel="nofollow">wikipedia entry</a> describes the flood fill algorithm and how it applies to solving the problem of finding connected regions of a graph. </p> <p>To see how the original question can be made into a question on graphs: make each entry (e.g. "Server1", "Server_1", etc.) a node on a graph. Connect nodes with edges if and only if they are synonyms. A matrix data structure is particularly appropriate for keeping track of the edges, provided you have enough memory. Otherwise a sparse data structure like a map will work, especially since the number of synonyms will likely be limited. </p> <ul> <li>Server1 is Node #0 </li> <li>Server_1 is Node #1</li> <li>Server_2 is Node #2</li> </ul> <p>Then edge[0][1] = edge[1][0] = 1, indicated that there is an edge between nodes #0 and #1 ( which means that they are synonyms ). While edge[0][2] = edge[2][0] = 0, indicating that Server1 and Server_2 are <strong>not</strong> synonyms.</p> <p><strong>Complexity Analysis</strong></p> <p>Creating this data structure is pretty efficient because a single linear pass with a lookup of the mapping of strings to node numbers is enough to crate it. If you store the mapping of strings to node numbers in a dictionary then this would be a O(n log n) step. </p> <p>Doing the flood fill is O(n), you only visit each node in the graph once. So, the algorithm in all is O(n log n).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload