Explore BrainMass

Describing Algorithms

Suppose you are given a list of n integers in random order. Describe an algorithm that will determine whether the numbers would be an arithmetic progression if they were sorted. Note: An arithmetic progression is a set of numbers of the form {a + bj | j = 0, 1, 2, ... n - 1} where a and b are both integers. To get any marks your algorithm must run in O(n) time.

Please show me detailed processes, thank you.

Solution Preview

1. Enter the n numbers one at a time in a "for loop" construct (O(n)).
2. The numbers are sorted in the numerical order using any O(n) algorithm, and the sorted sequence is stored in an array.
3. An arithmetic progression is a sequence of ...

Solution Summary

This solution provides a step by step method for describing an algorithm.