Question: Given an array A of N distinct integers sorted in increasing order, we seek an algorithm to determine if there exist two integers in A

Given an array A of N distinct integers sorted in increasing order, we seek an algorithm to determine if there exist two integers in A that sum to k. The algorithm returns TRUE if such a pair exists, and FALSE otherwise.

  1. Give an exhaustive algorithm and obtain its running time in the worst case. Complete method sum_exh() in file sum.java.
  2. Give a more efficient recursive algorithm and obtain its running time in the worst case. Complete method sum_rec() in file sum.java.

Submit only file sum.java. Use the main program sum_main.java and input data file sum.in to test your program. Check file sum.out for the correct output

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!