Consider the following function:
import Data.List (find)
findInLists items = map $ find (`elem` items)
Which can be called like so with the following result:
findInLists [2,3] [[1,2], [1,3,2], [4, -2, 8]] -> [Just 2, Just 3, Nothing]
The first argument can be assumed to be sorted, but the second argument will not be sorted.
If n is the total number of items in all lists to be searched (in this particular case, 7, as the search stops once an item is found) and k is the number of items to search for, I believe the runtime of this function will be O(n * k). However, this is bad for large k when n is also large.
I would like the runtime to be more like O(n * log k) + O(k * log k) or better if possible. What’s the best way to do this?
Stick the
itemsin aSetand usemember.