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

Function xlsread - file function, Function xlsread - file function: Th...

Function xlsread - file function: The function xlsread will read from the spreadsheet file. For illustration, to read from file just generated: >> ssnums = xlsread('ranexc

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

Sorting, Sorting The Sorting is a process of putting a list in order; ...

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 li

Matlab program - error-checking for integers, Error-checking for integers: ...

Error-checking for integers: illustrations of running this script as shown below: >> readoneint Enter an integer: 9.5 Invalid! Enter an integer: 3.6 Invalid

Cholesky factorisation of packed storage matrix, If I have a vector represe...

If I have a vector representing the packed storage form of a symmetric matrix, how do I perform a cholesky factorisation on that?

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

Example of recursive functions, Example of Recursive functions: This d...

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

Strings as vectors, Strings as Vectors: The Strings are considered as ...

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

Use of logical vector, Use of logical vector: Determine how many eleme...

Use of logical vector: Determine how many elements in the vector vec were greater than 5, the sum function can be used on the resulting vector isg: >> sum(isg) ans =

Illustrations of variable number of output arguments, Illustrations of Vari...

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

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