Explore BrainMass

Describe an Algorithm

The question is attached and there are some clarifications

1. The integers are NOT sorted and you CANNOT sort them. You need to see if the numbers would match the pattern if you were to sort them.
2. a and b can be any integer and we don't know the values in advance.


Solution Preview

The basic idea is to find a and b in O(n) time.
Here is the description of the algorithm, with input array A[1..n] of n integers.
Step 1: Find the smallest element y1 in A[1..n], this will take O(n) time.
Step 2: Find the largest element y2 in A[1..n], this will take O(n) time
If y1=y2, then return true. ...

Solution Summary

The solution describes an algorithm.