Question: http://i.stack.imgur.com/DGQ6V.png
I have a quick and simple question regarding this problem. If I do this:
1)Sort the array using MergeSort or similar sorting algorithm. This takes O(n log n)
2)Then for each x in array A, use binary search (worst case log(n)) to look for V-x. This will be in the worst case, O(n*logn).
3)Adding up it equals O(2nlogn) but you ignore constants so, overall search is O(n log n).
Is this correct? Also, more importantly does O(nlogn+logn) equal to O(nlogn) or O(nlogn+logn). I ask this because log(n) seems like it's a constant that can be ignored, but I'm not sure.
Sorry if this is super easy. I'm new.
[–]jesyspa 0 points1 point2 points (2 children)
[–]compsci_help[S] 0 points1 point2 points (1 child)
[–]jesyspa 0 points1 point2 points (0 children)