Sorting, MATLAB in Mathematics

Assignment Help:

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.


Related Discussions:- Sorting

Creating string variables, Creating string Variables: The string consi...

Creating string Variables: The string consists of a few numbers of characters (including, possibly, none). These are the illustrations of the strings: '' 'x' 'ca

Example of symbolic expression, Example of Symbolic Expression When the...

Example of Symbolic Expression When there is more than one variable, the MATLAB selects which to solve for. In the illustration below, the equation ax 2 + bx = 0 is solved. Th

Differentiation, Differentiation: The derivative of a function y = f(x...

Differentiation: The derivative of a function y = f(x) can be written as follows or f  '(x) and is defined as the rate of change of the dependent variable y with respe

Illustration of a recursive function, Illustration of a recursive function:...

Illustration of a recursive function: illustration is of a recursive function which does not return anything, but simply prints. The below function prtwords receives a sentenc

Nested if-else statements, Nested IF-ELSE statements: The if-else stat...

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

Fliplr function - changing dimensions, Fliplr function: The fliplr fun...

Fliplr function: The fliplr function "flips" the matrix from left to right (in another words the left-most column, the first column, become the last column and so on), and the

Writing variables to a file, Writing variables to a File: The save com...

Writing variables to a File: The save command is used to write variables to a file, or to append the variables to a MAT-file. By the default, save function writes to a MAT-fil

Use of string variables, Use of string variables: The Characters invol...

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

Structure consisting of the fields, Structure Consisting of the Fields ...

Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

Illustration of writing to files, Illustration of Writing to files: He...

Illustration of Writing to files: Here is the other illustration in which a matrix is written to a file. At First, an arbitrary 2 × 4 matrix is generated, and then it is writt

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd