SlideShare a Scribd company logo
2
Most read
9
Most read
13
Most read
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

PDF
Algorithms Lecture 4: Sorting Algorithms I
PDF
Algorithms Lecture 6: Searching Algorithms
PPTX
Introduction to Embedded Systems
PPTX
sorting and its types
PPTX
trees in data structure
PPTX
Linked List
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPTX
Seven principles of effective writing
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 6: Searching Algorithms
Introduction to Embedded Systems
sorting and its types
trees in data structure
Linked List
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Seven principles of effective writing

What's hot (20)

PPTX
Binary Search Tree in Data Structure
PPTX
Data Structures (CS8391)
PPT
SEARCHING AND SORTING ALGORITHMS
PPT
Data Structures- Part5 recursion
PPT
Linked List
PPT
Abstract data types
PPTX
PPTX
heap Sort Algorithm
PPTX
Hashing
PPT
Bubble sort
PDF
Binary Search - Design & Analysis of Algorithms
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Searching
PPTX
Hashing Technique In Data Structures
PPT
Divide and Conquer
PPTX
Abstract Data Types
PPTX
linked list in data structure
PDF
Sorting Algorithms
PPTX
Bubble Sort Algorithm Presentation
PPTX
Graph representation
Binary Search Tree in Data Structure
Data Structures (CS8391)
SEARCHING AND SORTING ALGORITHMS
Data Structures- Part5 recursion
Linked List
Abstract data types
heap Sort Algorithm
Hashing
Bubble sort
Binary Search - Design & Analysis of Algorithms
BINARY TREE REPRESENTATION.ppt
Searching
Hashing Technique In Data Structures
Divide and Conquer
Abstract Data Types
linked list in data structure
Sorting Algorithms
Bubble Sort Algorithm Presentation
Graph representation
Ad

Viewers also liked (20)

PPT
Sorting Seminar Presentation by Ashin Guha Majumder
PPT
Sorting Algorithms
PPTX
Sorting Algorithm
PDF
Sorting algorithms
PPTX
Marge Sort
PPTX
Different Sorting tecniques in Data Structure
PPTX
BUCKET SORT
PPTX
Lecture 12 data structures and algorithms
PPT
(Data Structure) Chapter11 searching & sorting
PPTX
Bucket sort- A Noncomparision Algorithm
PPTX
Binary search
PPTX
Lecture 13 data structures and algorithms
PPTX
Lecture 14 data structures and algorithms
PPTX
Shell sort
PPT
Linear Search & Binary Search
PPT
PDF
Linear search algorithm
PPTX
Linear Search Data Structure
ODP
Sorting Algorithm
Sorting Seminar Presentation by Ashin Guha Majumder
Sorting Algorithms
Sorting Algorithm
Sorting algorithms
Marge Sort
Different Sorting tecniques in Data Structure
BUCKET SORT
Lecture 12 data structures and algorithms
(Data Structure) Chapter11 searching & sorting
Bucket sort- A Noncomparision Algorithm
Binary search
Lecture 13 data structures and algorithms
Lecture 14 data structures and algorithms
Shell sort
Linear Search & Binary Search
Linear search algorithm
Linear Search Data Structure
Sorting Algorithm
Ad

Similar to Sorting Algorithms (20)

PPT
Data Structures 6
PDF
Class13_Quicksort_Algorithm.pdf
PPT
03_sorting123456789454545454545444543.ppt
PPT
03_sorting and it's types with example .ppt
PPT
quicksortnmsd cmz ,z m,zmm,mbfjjjjhjhfjsg
PPTX
sorting-160810203705.pptx
PPTX
Lecture 11.2 : sorting
PPTX
PPTX
sorting-160810203705.pptx
PPTX
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
PPT
Data Structure (MC501)
PPT
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
PPT
Searching Sorting-SELECTION ,BUBBBLE.ppt
PDF
Sorting
PPTX
SORT AND SEARCH ARRAY WITH WITH C++.pptx
PPT
PPTX
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
PPTX
Sorting algorithms
PPTX
Introduction to Algorithms
Data Structures 6
Class13_Quicksort_Algorithm.pdf
03_sorting123456789454545454545444543.ppt
03_sorting and it's types with example .ppt
quicksortnmsd cmz ,z m,zmm,mbfjjjjhjhfjsg
sorting-160810203705.pptx
Lecture 11.2 : sorting
sorting-160810203705.pptx
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
Data Structure (MC501)
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Searching Sorting-SELECTION ,BUBBBLE.ppt
Sorting
SORT AND SEARCH ARRAY WITH WITH C++.pptx
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Sorting algorithms
Introduction to Algorithms

Recently uploaded (20)

PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Sustainable Sites - Green Building Construction
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Model Code of Practice - Construction Work - 21102022 .pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
additive manufacturing of ss316l using mig welding
Foundation to blockchain - A guide to Blockchain Tech
OOP with Java - Java Introduction (Basics)
CYBER-CRIMES AND SECURITY A guide to understanding
R24 SURVEYING LAB MANUAL for civil enggi
Internet of Things (IOT) - A guide to understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Operating System & Kernel Study Guide-1 - converted.pdf
bas. eng. economics group 4 presentation 1.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Mechanical Engineering MATERIALS Selection

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.