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

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

View Full Document Right Arrow Icon
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
Background image of page 1
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

This document was uploaded on 11/18/2009.

Ask a homework question - tutors are online