What is the computational complexity of your answer in Question 1? Can you explain why?
- O(n^2)
- O(nlogn)
- O(n)
- O(logn)
Answer:
O(n^2), The worst case would be if the 2nd array is the subset of the 1st array; In that case, we should go all over every item of the 1st array to check for every item of the 2nd array, which takes a * b steps (a: length of the 1st array, b: length of the 2nd array). So the space complexity would be O(n^2)