A simple modification to merge sort will do the trick. Merge sort is O(n log n). It's also stable, meaning that items with equal keys will remain in their same relative order. The only difference here is that you want to eliminate duplicates. The only change to the code is in the comparison and copying of items. For example, the inner loop of a standard merge sort looks like this:
while (leftIndex < leftMax && rightIndex < rightMax)
{
if (a[leftIndex] <= a[rightIndex])
{
output[outputIndex] = a[leftIndex];
++leftIndex;
}
else
{
output[outputIndex] = a[rightIndex];
++rightIndex;
}
}
You would modify the code so you don't copy equal items:
while (leftIndex < leftMax && rightIndex < rightMax)
{
if (a[leftIndex] < a[rightIndex])
{
output[outputIndex] = a[leftIndex];
++leftIndex;
}
else if (a[leftIndex] > a[rightIndex])
{
output[outputIndex] = a[rightIndex];
++rightIndex;
}
else
{
// items are equal.
// increment the right, but don't copy anything
++rightIndex;
}
}
You could also do this with a standard merge sort and then do a final pass over the sorted array to remove duplicates.
You could use Quicksort with a custom comparison function that compares the telephone number and the date/time. Then do a final pass over the sorted array to remove duplicates.
Both Quicksort and Mergesort are considered divide and conquer algorithms.