Sorting, MATLAB in Mathematics

Sorting

The Sorting is a process of putting a list in order; either in descending (maximum to minimum), or ascending (minimum to maximum) order. For illustration, here is a list of n integers, imagine as a column vector.

1834_sorting.png

We want to sort it in ascending order in place, in another word, rearranging this vector, not creating the other. The one basic algorithm would be as shown below:

¦ Look throughout the vector to find the minimum number, and then place it in the first element in the vector. How? By replacing it with the number presently in the first element.

¦ Then, scan the rest of the vector (from the second element down) looking for the next minimum (or, the lowest in the rest of the vector). Whenever found, put it in the first element of the rest of the vector.

¦ Continue doing this for the rest of the vector. The next-to-last number has been once placed in the correct place in the vector, also by default the last number.

The table below shows the progression. The left-hand column represents the original vector. The second column (from left) represents that the minimum number, that is 70, is now in the first element in the vector. It was place there by replacing with what had been in the first element, 85. This carries on element-by-element, till the vector has been sorted.

1603_sorting1.png

This is known as the selection sort; it is merely one of several different sorting algorithms.

Posted Date: 10/22/2012 7:21:35 AM | Location : United States







Related Discussions:- Sorting, Assignment Help, Ask Question on Sorting, Get Answer, Expert's Help, Sorting Discussions

Write discussion on Sorting
Your posts are moderated
Related Questions
Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg

Creating Customized strings: There are many built-in functions which create customized strings, including blanks, char, and sprintf. We know that the char function can be u

Recursive Functions: The Recursion occurs whenever something is defined in terms of itself. In the programming, a recursive function is a function which calls itself. The Recu

Types of User-defined Functions: We know how to write a user-defined function, stored in an M-file, which computes and returns one value. This is merely one type of the functi

The variance is generally defined in terms of the arithmetic mean as: At times, though, the denominator is defined as n instead of n - 1. The default definition used by t

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func

User input in the while loop: Here is an illustration of running this script: >> readonenum Enter a positive number: -5 Invalid! Enter a positive number: -2.2

Strings as Vectors: The Strings are considered as vectors of characters-or in another words, a vector in which each and every element is a single character-so numerous vector

Illustrations of Variable number of output arguments: In the illustrations shown here, the user should actually know the type of the argument in order to establish how many va

Counting in a While Loop: Whenever it is not known ahead of the time how many values will be entered into the script, it is often essential to count the number of values which