# Coding Challenge - Build a Median Machine

Publish Date: Jan 05, 2011 | 0 Ratings | 0.00 out of 5 |  PDF

### Build a Median Machine!

Your mission, should you choose to accept it, is to develop a VI which quickly determines the median value in an array of up to 3,000,000 unsorted double-precision numbers which range from 0 - 1,000.

In statistics, the median is that value that separates the highest half of the sample from the lowest half. To find the median, arrange all the observations from lowest value to highest value and pick the middle one. If there is an even number of elements, take the mean of the two middle values.

As an additional challenge, you may not use any of the array-sorting VIs in LabVIEW (Sort 1-D Array.vi, Sort 1-D Array PtByPt.vi, Sort Complex Numbers.vi, etc). If you wish to sort the array, you must develop your own array-sorting algorithm. Nor can you use any of the median VIs in LabVIEW (Median.vi, Median PtByPt.vi, Median Filter.vi, Median Filter PtByPt.vi, etc).

As an example of determining the median of an unsorted array, suppose we receive an input array of <1, 3, 0>. If we sort this array, we get <0, 1, 3> and so the median value, which is in the middle, is 1. Furthermore, suppose our input array is <3, 8, 4, 0, 14, 6>. When we sort this array, it gives us <0, 3, 4, 6, 8, 14>. Since this array has an even number of elements, we average the middle two elements, and so the median is 5.

Scores will be based on accuracy and speed of the VI and the coding style. For help with coding style, see Chapter 6 of the LabVIEW Development Guidelines.

Hint: There are almost as many sorting algorithms as there are programmers. Many of these are searchable on the Internet. That is a great place to start.

Rules Specific to this Challenge

1. All coding must be done in LabVIEW.
2. No external code, DLLs, CINs, exes, etc
3. You may not use any of the array-sorting VIs in LabVIEW (Sort 1-D Array.vi, Sort 1-D Array PtByPt.vi, Sort Complex Numbers.vi, etc). Nor can you use any of the median VIs in LabVIEW (Median.vi, Median PtByPt.vi, Median Filter.vi, Median Filter PtByPt.vi, etc).
4. Have fun!

Good luck, wireworkers!

Discuss this challenge on the Discussion Forums

### Other Info

Ask questions and share ideas on this challenge in the Discussion Forums.   See the results of Past Coding Challenges

#### Ratings

Rate this document