# ex1 - interested in their relative order Can a linear-time...

This preview shows page 1. Sign up to view the full content.

CSE5311 Design and Analysis of Algorithms Exercise Problems 1 01/18/07 1. Given an array of integers A [1.. n ], such that, for all i , 1 i < n , we have A [ i ]- A [ i +1] 1. Let A [1] = x and A [ n ] = y , such that x < y . Design an efficient search algorithm to find j such that A [ j ] = z for a given value z , x z y . What is the maximal number of comparisons to z that your algorithm makes? 2. The input is a set S containing n real numbers, and a real number x . a. Design an algorithm to determine whether there are two elements of S whose sum is exactly x . The algorithm should run in O ( n log n ) time. b. Suppose now that the set S is given in a sorted order. Design an algorithm to solve the above problem in time O( n ). 3. Suppose we are to find the k smallest elements in a list of n elements, and we are not
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: interested in their relative order. Can a linear-time algorithm be found when k is a constant? If so give the algorithm. In either case, justify your answer. 4. Consider a set S of n ≥ 2 distinct numbers given in unsorted order. Give an algorithm to determine two distinct numbers x and y ( x ≠ y ) exist in the set S such that x-y ≤ w-z for all w , z ∈ S and w ≠ z . Your algorithm should run in O ( n log n ) time. 5. The input is d sequences of elements such that each sequence is already sorted, and there is a total of n elements. Design an O ( n log d ) algorithm to merge all the sequences into one sorted sequence. << Solutions in Class>>...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern