I have two NSArrays of Movie objects called DVD and VHS. I’d like to find the symmetric difference of these arrays. I want to know which Movies are in VHS buy not in DVD, and which Movies are in DVD but not VHS.
Can anyone tell me if there is a fast algorithm to solve it (preferably in C or Objective-C)? Is it faster/easier to solve if I use Dictionaries? What this kind of problem called (or is it just “Symmetric Difference”)?
Thanks.
You might get better results using
NSSetrather thanNSArray, depending on whether or not you want to allow duplicates in your lists.NSSetgives you methods likeintersectsSet:which should give you what you need.If you need union functionality, you can use
NSMutableSet.