Question: 6. (15 points) Array A contains n integers. Given an integer s, find whether or not there exist two elements x and y in the
6. (15 points) Array A contains n integers. Given an integer s, find whether or not there exist two elements x and y in the array such that the sum of the two numbers is s, that is x+y = s. (a) Describe an O(n 2 ) time algorithm to solve the problem and write the pseudocode. (b) Assuming it is possible to sort n numbers in O(n log n) time, describe an O(n log n) time algorithm to solve the problem and write the pseudocode. In the pseudocoe, assume a function sort(A) is available.
6. (15 points) Array A contains n integers. Given an integer s, find whether or not there exist two elements x and y in the array such that the sum of the two numbers is s, that is x+y=s. (a) Describe an O(n?) time algorithm to solve the problem and write the pseudocode. (b) Assuming it is possible to sort n numbers in O(n log n) time, describe an O(n log n) time algorithm to solve the problem and write the pseudocode. In the pseudocoe, assume a function sort(A) is available
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
