Perform Joins in O(n) time?
问题 is there a way to Join 2 tables in linear time? I heard this can be done by having another data structure (Hashtable), but I'm not sure how this can be done. I was always wondering a Join will involve a cross-product and hence it is O(n^2). 回答1: Algorithm: Loop through table A. Hash all Items, Add them to the Join array. Loop through table B, check each item if it's in the hash table (Check - O(1)), if not, add to the Join table. 回答2: If there are indexes available on columns used in the join