The program for finding the two numbers in the array sum up to x is made.
Explain the term sorting?
- Sorting involves putting data into a meaningful order so how you can more efficiently evaluate it.
- For instance, if you want to plot a graph of sales performance, you could wish to sort the sales data per calendar month.
Array A[n], x
- Sort by the use of Mergesort ------- O(nlogn)
- Initialize 2 index variables to estimate candidit.
- Initialize 1st to that leftmost index: l = 0
- Initializ 2nd to that rightmost index: r = n - 1
- While l < r -----------O(n)
- if A[l] + A[r] == x; return true
- else if A[l] + A[r] < sum; increment l
- else decrement r
- return false
Time Complexity:
As was covered in class, step one employs mergesort, which has an O(nlogn) complexity.
Since the worst-case scenario involves traversing through the full array, step three consumes O(n) time.
Total Running Time = O(nlogn + n) = O(nlogn)
Thus, the program for finding the two intergers in the array sum up to x is made.
To know more about the sorting, here
https://brainly.com/question/1385135
#SPJ4