IDNLearn.com offers a collaborative platform for sharing and gaining knowledge. Join our community to access reliable and comprehensive responses to your questions from experienced professionals.
Sagot :
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
Your engagement is important to us. Keep sharing your knowledge and experiences. Let's create a learning environment that is both enjoyable and beneficial. Your questions deserve accurate answers. Thank you for visiting IDNLearn.com, and see you again for more solutions.