Professional Documents
Culture Documents
Sorting and Its Types
Sorting and Its Types
And Its
Types
SORTING
Sortingrefers to operations of
arranging a set of data in a given
order.
30 10 60 20 50 40 Unsorted List
10 20 30 40 50 60 Sorted List
BASIC TYPES :
Internal Sorting:
If all the data to be sorted can be
adjusted in main memory then it is
called as Internal Sorting.
External Sorting:
If data to be stored is large and aquires
external memory then the type is called
as External Sorting.
METHODS OF SORTING:
Bubble Sort
Selection Sort
Insertion Sort
BUBBLE SORT
ALGORITHM
Bubble Sort:
Algorithm of bubble sort includes two steps
repeated until the list is sorted.
Compare adjacent elements, if the
element on right side is smaller then
swap their positions.
Compare first element, second element
and so on on completion of Pass 1 the
largest element is at last position.
50 10 30 20 40
50 10 30 20 40 0,1
10 50 30 20 40 1,2
10 30 50 20 40 2,3
10 30 20 50 40 3,4
10 30 20 40 50
Pass 2:
10 30 20 40 50 0,1
10 30 20 40 50 1,2
10 30 20 40 50 2,3
10 30 20 40 50
Pass 3:
10 30 20 40 50 0,1
10 30 20 40 50 1,2
10 30 20 40 50
Pass 4:
10 30 20 40 50 0,1
10 30 20 40 50
10 30 20 40 50 Sorted list
SELECTION SORT
ALGORITHM
Selection Sort:
Here in selection sort the algorithm depends on the
zeroth element majorly.
1:
23 15 29 11 1 0,1
15 23 29 11 1 0,2
15 23 29 11 1 0,3
11 23 29 15 1 0,4
1 23 29 15 11
Pass 2:
1 23 29 15 11
1,2
1 29 23 15 11 1,3
1 15 23 29 11 1,4
1 11 23 29 15
Pass 3:
1 11 23 29 15 2,3
1 11 23 29 15 2,4
1 11 15 29 23
Pass 4:
1 11 15 29 23 3,4
1 11 15 23 29
1 11 15 23 29 Sorted List
INSERTION SORT
This method is effective when dealing
with small numbers .
75 57 25 19 4 0,1
57 75 25 19 4
Pass 2:
57 75 25 19 4 0,2
25 57 75 19 4
Pass 3:
25 57 75 19 4 0,3
19 25 57 75 4
Pass 4:
19 25 57 75 4 0,4
4 19 25 57 75
Thank You…!