If your lists do not change often, you can sort both lists and then merge in linear time simply by going through both lists.
If your lists change all the time, you probably would be better off sorting a βsmallβ container, like map or set . In this case, just use find in the set for each item in the large list that you want to join.
source share