SlideShare a Scribd company logo
1 of 24
Chameli Devi School Of Engineering
CSE Department
Presentation On
Presented By- Pranay Neema
Sorting Algorithms
Algorithm
• An algorithm is a procedure or formula for solving a
problem.
• The word derives from the name of the mathematician,
Mohammed ibn-Musa al-Khwarizmi
Algorithm Complexity
• Most of the primary sorting algorithms run on different space
and time complexity.
• Time Complexity is defined to be the time the computer takes
to run a program (or algorithm in our case).
• Space complexity is defined to be the amount of memory the
computer needs to run a program.
Complexity Conti..
• Complexity in general, measures the algorithms efficiency in
internal factors such as the time needed to run an algorithm.
• External Factors (not related to complexity):
o Size of the input of the algorithm
o Speed of the Computer
o Quality of the Compiler
What is Sorting?
Sorting: an operation that segregates items into groups
according to specified criterion.
Example 1: A = { 3 1 6 2 1 3 4 5 9 0 }
A = { 0 1 1 2 3 3 4 5 6 9 }
Example 2: B={S B F A D T U}
B={A B D F S T U}
Types of Sorting Algorithms
There are many, many different types of sorting algorithms,
but the primary ones are:
Bubble Sort Selection Sort
Insertion Sort Merge Sort
Shell Sort Heap Sort
Quick Sort Radix Sort
Swap Sort
What’s Different in Sorting Algorithm
• Time Complexity
• Space Complexity
• Internal Sorting : The data to be sorted is all stored in the
computer’s main memory.
• External Sorting : Some of the data to be sorted might be
stored in some external, slower, device.
• In place Sorting : The amount of extra space required to sort
the data is constant with the input size.
Conti..
• Stable Sorting : It sort preserves relative order of records
with equal keys.
• Unstable Sorting : It doesn't preserves relative order.
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
90
98
98
86
75
86
90
Original array
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
90
98
98
86
75
86
90
Stably sorted
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
90
98
98
86
75
86
90
Original array
Bob
Ann
Joe
Zöe
Dan
Pat
Sam
90
98
98
86
75
86
90
Unstably sorted
Bubble Sort
• Simple and uncomplicated
• Largest element placer at last
• Compare neighboring elements
• Swap if out of order
• Two nested loops
• O(n2)
for (i=0; i<n-1; i++) {
for (j=0; j<n-1-i; j++)
if (a[j+1] < a[j]) { /* compare neighbors */
tmp = a[j]; /* swap a[j] and a[j+1] */
a[j] = a[j+1];
a[j+1] = tmp;
}
Selection Sort
• The list is divided into two sublists, sorted and unsorted.
• Search through the list and find the smallest element.
• swap the smallest element with the first element.
• repeat starting at second element and find the second smallest
element.
23 78 45 8 32 56
8 78 45 23 32 56
8 23 45 78 32 56
8 23 32 78 45 56
8 23 32 45 78 56
8 23 32 45 56 78
Original List
After pass 1
After pass 2
After pass 3
After pass 4
After pass 5
Sorted Unsorted
Selection Sort Algorithm
public static void selectionSort(int[] list)
{ int min;
int temp;
for(int i = 0; i < list.length - 1; i++) {
min = i;
for(int j = i + 1; j < list.length; j++)
if( list[j] < list[min] )
min = j;
temp = list[i];
list[i] = list[min];
list[min] = temp;
}
}
Insertion Sort
• Another of the O(N^2) sorts
• The first item is sorted
• Compare the second item to the first
• if smaller swap
• Third item, compare to item next to it need to swap
• after swap compare again
• And so forth…
Conti..
Quick Sort
• It is based on the principal of Divide-and-Conquer.
• It works as follows:
1. First, it partitions an array into two parts,
2. Then, it sorts the parts independently,
3. Finally, it combines the sorted subsequences by
a simple concatenation.
1. Divide: Partition the list.
2. Recursion: Recursively sort the sublists separately.
3. Conquer: Put the sorted sublists together.
Quicksort Example
13
81
92
43 31
65
57
26
75
0
13
81
92
43 31
65
57
26
75
0
13
43
31 57
26 0 81 92 7565
13 4331 57260 81 9275
13 4331 57260 65 81 9275
Select pivot
partition
Recursive call Recursive call
Merge
Merge Sort
• It is based on divide-and-conquer sorting algorithms.
• Requires an extra array memory.
• It is a recursive algorithm
o Divides the list into halves,
o Sort each halve separately, and
o Then merge the sorted halves into one sorted array.
o Both worst case and average cases are O (n * log2n )
Mergesort - Example
6 3 9 1 5 4 7 2
5 4 7 26 3 9 1
6 3 9 1 7 2
5 4
6 3 19 5 4 27
3 6 1 9 2 7
4 5
2 4 5 71 3 6 9
1 2 3 4 5 7 8 9
divide
dividedividedivide
dividedivide
divide
merge merge
merge
merge
merge merge
merge
Radix Sort – Example
•Non Comparison sorting algorithm.
•Time Complexity O(n).
Comparison
Future Scope
• An important key to algorithm design is to use sorting as a
basic building block, because once a set of items is sorted, many other
problems become easy.
• Sorting algorithm using Parallel processing.
• In future, we shall explore and support it with experimental results on
data which could not only be numeric but also text, audio, video, etc.
Conclusion
• Various use of sorting algorithm.
• Advancement in sorting algorithm day by day.
• Modification in previous algorithm.
• Each algorithm have it own importance.
THANKYOU….
Sorting Algorithms

More Related Content

What's hot

Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
MYER301
 

What's hot (20)

Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Quick sort
Quick sortQuick sort
Quick sort
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Binary search
Binary searchBinary search
Binary search
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Hashing
HashingHashing
Hashing
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Sorting And Type of Sorting
Sorting And Type of SortingSorting And Type of Sorting
Sorting And Type of Sorting
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 

Viewers also liked

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
multimedia9
 
Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithms
Aakash deep Singhal
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
Fadhil Ismail
 
Binary search
Binary search Binary search
Binary search
Raghu nath
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
Aakash deep Singhal
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
Aakash deep Singhal
 

Viewers also liked (20)

Sorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha MajumderSorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha Majumder
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Marge Sort
Marge SortMarge Sort
Marge Sort
 
Sorting
SortingSorting
Sorting
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 
BUCKET SORT
BUCKET SORTBUCKET SORT
BUCKET SORT
 
Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithms
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision Algorithm
 
Binary search
Binary search Binary search
Binary search
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Shell sort
Shell sortShell sort
Shell sort
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 

Similar to Sorting Algorithms

Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting Algorithm
Ashim Sikder
 

Similar to Sorting Algorithms (20)

Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & SearchingHub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
 
Sorting
SortingSorting
Sorting
 
16 mergesort
16 mergesort16 mergesort
16 mergesort
 
Lec35
Lec35Lec35
Lec35
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problems
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Algorithim lec1.pptx
Algorithim lec1.pptxAlgorithim lec1.pptx
Algorithim lec1.pptx
 
Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting Algorithm
 
Presentation merge sort.pptx
Presentation merge sort.pptxPresentation merge sort.pptx
Presentation merge sort.pptx
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

Sorting Algorithms

  • 1. Chameli Devi School Of Engineering CSE Department Presentation On Presented By- Pranay Neema Sorting Algorithms
  • 2. Algorithm • An algorithm is a procedure or formula for solving a problem. • The word derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi
  • 3. Algorithm Complexity • Most of the primary sorting algorithms run on different space and time complexity. • Time Complexity is defined to be the time the computer takes to run a program (or algorithm in our case). • Space complexity is defined to be the amount of memory the computer needs to run a program.
  • 4. Complexity Conti.. • Complexity in general, measures the algorithms efficiency in internal factors such as the time needed to run an algorithm. • External Factors (not related to complexity): o Size of the input of the algorithm o Speed of the Computer o Quality of the Compiler
  • 5. What is Sorting? Sorting: an operation that segregates items into groups according to specified criterion. Example 1: A = { 3 1 6 2 1 3 4 5 9 0 } A = { 0 1 1 2 3 3 4 5 6 9 } Example 2: B={S B F A D T U} B={A B D F S T U}
  • 6. Types of Sorting Algorithms There are many, many different types of sorting algorithms, but the primary ones are: Bubble Sort Selection Sort Insertion Sort Merge Sort Shell Sort Heap Sort Quick Sort Radix Sort Swap Sort
  • 7. What’s Different in Sorting Algorithm • Time Complexity • Space Complexity • Internal Sorting : The data to be sorted is all stored in the computer’s main memory. • External Sorting : Some of the data to be sorted might be stored in some external, slower, device. • In place Sorting : The amount of extra space required to sort the data is constant with the input size.
  • 8. Conti.. • Stable Sorting : It sort preserves relative order of records with equal keys. • Unstable Sorting : It doesn't preserves relative order. Bob Ann Joe Zöe Dan Pat Sam 90 98 98 86 75 86 90 Original array Bob Ann Joe Zöe Dan Pat Sam 90 98 98 86 75 86 90 Stably sorted Bob Ann Joe Zöe Dan Pat Sam 90 98 98 86 75 86 90 Original array Bob Ann Joe Zöe Dan Pat Sam 90 98 98 86 75 86 90 Unstably sorted
  • 9. Bubble Sort • Simple and uncomplicated • Largest element placer at last • Compare neighboring elements • Swap if out of order • Two nested loops • O(n2) for (i=0; i<n-1; i++) { for (j=0; j<n-1-i; j++) if (a[j+1] < a[j]) { /* compare neighbors */ tmp = a[j]; /* swap a[j] and a[j+1] */ a[j] = a[j+1]; a[j+1] = tmp; }
  • 10. Selection Sort • The list is divided into two sublists, sorted and unsorted. • Search through the list and find the smallest element. • swap the smallest element with the first element. • repeat starting at second element and find the second smallest element.
  • 11. 23 78 45 8 32 56 8 78 45 23 32 56 8 23 45 78 32 56 8 23 32 78 45 56 8 23 32 45 78 56 8 23 32 45 56 78 Original List After pass 1 After pass 2 After pass 3 After pass 4 After pass 5 Sorted Unsorted
  • 12. Selection Sort Algorithm public static void selectionSort(int[] list) { int min; int temp; for(int i = 0; i < list.length - 1; i++) { min = i; for(int j = i + 1; j < list.length; j++) if( list[j] < list[min] ) min = j; temp = list[i]; list[i] = list[min]; list[min] = temp; } }
  • 13. Insertion Sort • Another of the O(N^2) sorts • The first item is sorted • Compare the second item to the first • if smaller swap • Third item, compare to item next to it need to swap • after swap compare again • And so forth…
  • 15. Quick Sort • It is based on the principal of Divide-and-Conquer. • It works as follows: 1. First, it partitions an array into two parts, 2. Then, it sorts the parts independently, 3. Finally, it combines the sorted subsequences by a simple concatenation. 1. Divide: Partition the list. 2. Recursion: Recursively sort the sublists separately. 3. Conquer: Put the sorted sublists together.
  • 16. Quicksort Example 13 81 92 43 31 65 57 26 75 0 13 81 92 43 31 65 57 26 75 0 13 43 31 57 26 0 81 92 7565 13 4331 57260 81 9275 13 4331 57260 65 81 9275 Select pivot partition Recursive call Recursive call Merge
  • 17. Merge Sort • It is based on divide-and-conquer sorting algorithms. • Requires an extra array memory. • It is a recursive algorithm o Divides the list into halves, o Sort each halve separately, and o Then merge the sorted halves into one sorted array. o Both worst case and average cases are O (n * log2n )
  • 18. Mergesort - Example 6 3 9 1 5 4 7 2 5 4 7 26 3 9 1 6 3 9 1 7 2 5 4 6 3 19 5 4 27 3 6 1 9 2 7 4 5 2 4 5 71 3 6 9 1 2 3 4 5 7 8 9 divide dividedividedivide dividedivide divide merge merge merge merge merge merge merge
  • 19. Radix Sort – Example •Non Comparison sorting algorithm. •Time Complexity O(n).
  • 21. Future Scope • An important key to algorithm design is to use sorting as a basic building block, because once a set of items is sorted, many other problems become easy. • Sorting algorithm using Parallel processing. • In future, we shall explore and support it with experimental results on data which could not only be numeric but also text, audio, video, etc.
  • 22. Conclusion • Various use of sorting algorithm. • Advancement in sorting algorithm day by day. • Modification in previous algorithm. • Each algorithm have it own importance.