Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions