Consider the problem of finding the distance between the two closest numbers in an array of n numbers. The distance between two numbers x and y is computed as |x − y|.) (see Problem 9 in Exercises 1.2).
Problem 9 in Exercises 1.2
You can: decrease the number of times the inner loop is executed, make that loop run faster (at least for some inputs), or, more significantly, design a faster algorithm from scratch.
a. Design a presorting-based algorithm for solving this problem and determine its efficiency class.
b. Compare the efficiency of this algorithm with that of the brute-force algorithm
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here