Question: 4 Problem 4 (20 points total): Write an algorithm in pseudocode for each of following two problems below. Nothing else is needed just pseudocode. The

4 Problem 4 (20 points total):

Write an algorithm in pseudocode for each of following two problems below. Nothing else is needed just pseudocode. The algorithm should be simple in both cases!

Part 1: Closest Pair (10 points)

Input: An array A with n distinct (non-equal) elements

Output: numbers x and y in A that minimize |x y|, where |x y| denotes absolute-value(x-y). (If there are multiple closest pairs, you only have to return one of them.) 2 The run-time should be significantly better than O(n^2).

Part 2 (10 points): Given an array A of size n, write pseudocode for algorithm FindMax(A) that computes the maximum value in A. The run-time should be O(n).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!