You could put all elements of the first list into a hash set. Then, iterate the second one and, for each of its elements, check the hash to see if it exists in the first list. If so, output it as an element of the intersection.
More Related Contents:
- Algorithm to generate all possible permutations of a list?
- Computing set intersection in linear time?
- Efficiently selecting a set of random elements from a linked list
- Complexity of absolute difference and sum
- Efficient way to add element to sorted datastructure [closed]
- What is tail recursion?
- Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping
- Getting the closest string match
- How do you detect Credit card type based on number?
- How to compute Discrete Fourier Transform?
- How does finding a cycle start node in a cycle linked list work?
- find all subsets that sum to a particular value
- Need help in mod 1000000007 questions
- What is Constant Amortized Time?
- SICP example: Counting change, cannot understand
- How can I compute a Cartesian product iteratively?
- Quicksort: Iterative or Recursive
- How best to sum up lots of floating point numbers?
- Polygon enclosing a set of points
- Algorithm to mix sound
- finding a^b^c^… mod m
- Algorithm to find the most common substrings in a string
- Sorting a sequence by swapping adjacent elements using minimum swaps
- Optimizing Conway’s ‘Game of Life’
- Retrieving the top 100 numbers from one hundred million of numbers [duplicate]
- What is password hashing? [closed]
- Can an array be grouped more efficiently than sorted?
- Why are hash table expansions usually done by doubling the size?
- Find local minimum in n x n matrix in O(n) time
- What is the difference between Linear search and Binary search?