explanation of solution
The solution seems to be the the following, but I need a more in-depth explanation, particularly on why we should use merge sort and binary sort.
Here is the problem at a high level (you can look at the attachment for more detail):
Describe a (n log_2 n) time algorithm that, given a set S of n real numbers
and another real number x, determines whether or not there exist two
elements in S whose sum is exactly x.
Solution:
Sort the array using an algorithm of order O(n log n) (You can use mergesort but
you cannot use quicksort)
Then for every element y in the array binary search the sorted array for x - y
O(n log n) + O(n log n) = O(n log n)
By OTA: Xiao Liu, MS
OTA Rating: 4.7/5
Your Price: $2.19 (original value ~$15.96)
What's included:
Page generated in 0.0138 seconds