=2) distinct natural numbers, design an effic” src=”https://files.transtutors.com/cdn/qimg/40150ba9c271476cba0d84e7064d0169.jpg” aria-describedby=”j2e”>

3. Algorithm Design (20 points) Consider an unsorted array A that contains n (n>=2) distinct natural numbers, design an efficient algorithm to determine if the array contains two integers such that they add up to a specific target number s. That is: if we can find A[i] A[j] = s ( 1 s i, j sn, i #, s is an integer, the algorithm should return TRUE, otherwise return FALSE Design requirement: the efficient algorithm you are going to design should provide a lnear running time, rather than a O(n2) running-time brute-force solution or a 0(nlgn) solution. You may use the algorithms that we learned in the textbook. (1) Write the Pseudo-code (please use textbook conventions) (15 points) (2) Justify the running time of the algorithm (5 points)



Source link

Leave a Reply

Your email address will not be published.