Top Banner
SORTING (1) Sorting---Overview:- I/p :- A sequence <a 1 a 2 … a n > O/p :- A permutation of i/p < a 1’ a 2’ … a n’ > such that a i’ <= a i+1’ , for 1<=i’<n where each a i belongs to a domain on which sorting is defined in one or the other way . For example, sorting is defined on the set of real numbers where sorting is generally considered to be sorting by magnitude of the numbers. i.e ¾ is considered to be higher in order than ½ and -¾ is considered to be lower than -½. This does not mean that sorting can not be done a domain on which such natural concept like magnitude of an element is not defined. We can force or define our own customized notion of magnitude on the domain in such cases, of course depending on requirement and if such a notion can really be created. For ex. consider a 2 dimensional figure, a square of width 4, with left bottom corner located at the zero of the Cartesian 2 dimensional geometry. Consider 2-dimensional points (x,y) inside or on border of this square where x and y are positive integers. Call this set as INT(square), meaning the collection of all points inside or on the boundary of the square where co-ordinates can take only integral values. So, INT(square)={(0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2), (1,2), (2,2), (3,2), (0,3), (1,3), (2,3), (3,3)} . Now, there does not exist any immediate obvious concept like magnitude of a n-dimensional point on which we can sort the above set. Given (1,3) and (2,2), we do not know which one is greater so that we can sort this pair. So, we can define our own notion of magnitude. For example, consider magnitude of a point (x,y) to be the formula |(x,y)|=|x|+|y| i.e sum of absolute values of co-
31

Sorting Methods - partial

Nov 12, 2015

Download

Documents

sunil-shelke

partial notes on sorting methods
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

SORTING

(1) Sorting---Overview:-

I/p:- A sequence

O/p:- A permutation of i/p < a1 a2 an > such that ai