Computers and Technology

(20 points) Let A[1::n] be an array of distinct positive integers, and let t be a positive integer. (a) (10 points) Assuming that A is sorted, show that in O(n) time it can be decided if A contains two distinct elements x and y such that x + y = t. (b) (10 points) Use part (a) to show that the following problem, re- ferred to as the 3-Sum problem, can be solved in O(n2) time: 3-Sum Given an array A[1::n] of distinct positive integers, and a positive integer t, determine whether or not there are three distinct elements x, y, z in A such that x+y+z = t.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:00, Jana1517
What is the worst-case complexity of the maxrepeats function? assume that the longest string in the names array is at most 25 characters wide (i. e., string comparison can be treated as o( class namecounter { private: int* counts; int nc; string* names; int nn; public: namecounter (int ncounts, int nnames); int maxrepeats() const; }; int namecounter: : maxrepeats () { int maxcount = 0; for (int i = 0; i < nc; ++i) { int count = 1; for (int j = i+1; j < nc; ++j) { if (names[i] == names[j]) ++count; } maxcount = max(count, maxcount); } return maxcount; }
Answers: 3
image
Computers and Technology, 23.06.2019 04:20, RandomLollipop
Which network media uses different regions of the electromagnetic spectrum to transmit signals through air? uses different regions of the electromagnetic spectrum to transmit signals through air.
Answers: 2
image
Computers and Technology, 23.06.2019 22:30, ghari112345
Jamie has to enter the names, employee id’s, and income of a group of employees into a worksheet. which option will jamie use to describe the data
Answers: 3
image
Computers and Technology, 24.06.2019 16:50, yedida
Ideally, the backrest is tilted back slightly, so when you turn the wheel your shoulders are the seat.
Answers: 2
Do you know the correct answer?
(20 points) Let A[1::n] be an array of distinct positive integers, and let t be a positive integer....

Questions in other subjects:

Konu
Computers and Technology, 15.04.2021 21:50