Question: 1. (Adapted from Exercise 2.3-7 in the textbook) Write pseudocode for a (n Ig n-time algorithm that, given an array A of n integers and

 1. (Adapted from Exercise 2.3-7 in the textbook) Write pseudocode for

1. (Adapted from Exercise 2.3-7 in the textbook) Write pseudocode for a (n Ig n-time algorithm that, given an array A of n integers and another integerx, determines whether or not there exist two elements in A whose sum is exactly x. Explain informally why your algorithm is (n lg n)-time. You may use calls to the Merge-Sort algorithm in the textbook as part of your pseudocode. (Hint: Let p be the smallest element of A, r be the largest element of A, and z be any other element. Ifp+ x, what does tha say about z+?)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!