patternMinor
Determine whether two collections of items can be paired
Viewed 0 times
canpairedtwoitemscollectionsdeterminewhether
Problem
Given collections
And a pairing function that determines whether a slot can accept an item.
Is there an efficient way to find whether a "complete" pairing of items to slots exist, where "complete" means every slot is filled?
(More importantly for my use case... is there a way, other than trying every combination, to determine if no such pairing exists?)
I (items) and S (slots), where I >= S.And a pairing function that determines whether a slot can accept an item.
Is there an efficient way to find whether a "complete" pairing of items to slots exist, where "complete" means every slot is filled?
(More importantly for my use case... is there a way, other than trying every combination, to determine if no such pairing exists?)
Solution
Yes. You're just looking for a maximum matching in the bipartite graph where one side is the items, the other side is the slots and there's an edge between an item and each slot it's compatible with.
There are a number of efficient algorithms for this. The standard method taught to CS undergraduates is the augmenting paths algorithm of Hopcroft and Karp.
There are a number of efficient algorithms for this. The standard method taught to CS undergraduates is the augmenting paths algorithm of Hopcroft and Karp.
Context
StackExchange Computer Science Q#96583, answer score: 4
Revisions (0)
No revisions yet.