Merge Sort Algorithm

https://www.spoj.com/problems/PAIRS1/
Can we do this problem using merge sort algorithm. I have done this using binary search.

Last edited on
Why merge sort?
Why not std::sort?
You have used binary search. Binary search operates on sorted sequence. Therefore, you had a sorted sequence already. Now you ask about sorting?

There are multiple algorithms for sorting. They all have their strengths and weaknesses. Can you tell which suite for your problem and why?
In my experience, the only time you really NEED a sorted collection is when you must output the data in sorted order. For this problem I can think of a solution that runs in O(N) time and doesn't use sorting.
I mean to say that in merge sort algorithm we make a merge tree we find the answer while sorting. So can we do this problem like that.
And thank you for giving your time :)
Topic archived. No new replies allowed.