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

Rational function, Give the formula for a rational function that has a hole...

Give the formula for a rational function that has a hole at x=7 & vertical asmptote at x=-3/2

Illustration of empty vectors , Illustration of Empty vectors: The Emp...

Illustration of Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector

Plot functions, Plot Functions: Faraway, we have plotted to generate t...

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

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?

Logical vectors, Logical Vectors: The relational operators can also be...

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme

Standard deviation, Standard Deviation The standard deviation is the sq...

Standard Deviation The standard deviation is the square root of variance: The built-in function in a MATLAB for the standard deviation is known as std; the standard dev

Algebra, 5 p2+8p+15, 3 p2-3p-18, 12 p...

5 p2+8p+15, 3 p2-3p-18, 12 p2-p-30

Illustration of labels and prompts, Illustration of Labels and prompts: ...

Illustration of Labels and prompts: The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, th

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

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