Two sets of items. Each element of set A a unique match in set B. Match each item of set A to item in set B in O(nlogn) time

后端 未结 1 829
-上瘾入骨i
-上瘾入骨i 2021-01-13 11:59

So, to clarify the question:

Set A and Set B every element in set A has a partner in set B you can not sort either set based upon comparing it to members of the sa

相关标签:
1条回答
  • 2021-01-13 12:43

    You haven't stated it very clearly, but your question looks suspiciously like the Matching Nuts and Bolts problem.

    The idea there is to pick a random nut a, find the matching bolt b. Partition the bolts using nut a, and partition the nuts using Bolt b, and then recurse, like quicksort does.

    (Of course, we are talking about the average case being nlogn, rather than the worst case).

    0 讨论(0)
提交回复
热议问题