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
Example of Recursive functions: This definition is recursive as a factorial is defined in terms of the other factorial. There are two parts to any recursive definition: the co

Use of string variables: The Characters involve letters of the alphabet, punctuation marks, digits, white space, and control characters. The Control characters are characters

Plot Functions: Faraway, we have plotted to generate two-dimensional plots and bar to generate bar charts. We have seen how to clear the Figure Window by using clf, and how to

Built-in function for Differentiation: The MATLAB has a built-in function, diff that returns the differences between consecutive elements in a vector. For illustration, >>

Illustration of logical built-in functions: The function find returns the indices of a vector which meet certain criteria. For illustration, to find all the elements in a vect

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe

Built-in functions for Complex numbers:   We know that in MATLAB both i and j are built-in functions which return √-1 (therefore, they can be thought of as built-in constants).

Concatenation: The String concatenation means to join the strings altogether. Of course, as strings are merely vectors of the characters, the technique of concatenating vector

Three-dimensional pie and bar: For the bar3 function, x & y vectors are passed and the function displays three-dimensional bars as shown in figure: Figure: Three-dimen

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t