SlideShare a Scribd company logo
1 of 10
BIRLA VISHVAKARMA
MAHAVIDHYALAYA
Sorting in DATA STRUCTURE
Sr. No. Names Enrollment No.
1. Rudra Patel 140080116050
2. Rishab Shah 140080116054
3. Tushar Gonawala 140080116059
4. Rushang Patel 140080116064
PRESENTED TO: Prof. Vikram
SORTING
• Sorting is the process of ordering a list of elements in either ascending order or descending order.
• Sorting can be divided into two categories:
1. Internal Sorting: takes place in the main memory of the computer. It can take advantage of
the random access nature of the main memory. Element to be sorted is stored in an
integer array.
2. External Sorting: is carried on secondary memory. It becomes a necessity if the number of
elements to be sorted is too large to be fit in the main memory. Algorithm should always
take into account that movement of data between secondary storage and main storage is
best done by moving a block of contiguous element.
INSERTION SORT
• Insertion sort is based on the principle of inserting the element at its correct place in a previously
sorted list. It can be varied from 1 to n-1 to sort the entire array.
1st Iteration
0 5 1 9 2 6 4
2nd Iteration
0 1 5 9 2 6 4
3rd Iteration
0 1 5 9 2 6 4
4th Iteration
0 1 2 5 9 6 4
5th Iteration
0 1 2 5 6 9 4
6th Iteration
0 1 2 4 5 9 6
Sorted Unsorted
Sorted
Sorted
Sorted
Sorted
Sorted
Unsorted
Unsorted
Unsorted
Unsorted
ALGORITHM
void insertion_sort( int a[ ] , int n)
{
int I, j, temp;
for (i = 1 ; i < n ; i++)
{
temp = a[i];
for (j = i - 1 ; j >= 0 && a[j] > temp ; j--)
a[j + 1] = a[j];
a[j +1] = temp;
}
}
BUBBLE SORT
• Bubble sort is one of the simplest and the most popular sorting method. The basic idea behind
bubble sort is as a bubble rises up in water, the smallest element goes to the beginning. This
method is based on the successive selecting the smallest element through exchange of adjacent
element.
j = 0 5 6 2 8 1
j = 1 5 6 2 8 1
j = 2 5 2 6 8 1
j = 3 5 2 6 8 1
j = 0 5 2 6 1 8
j = 1 2 5 6 1 8
j = 2 2 5 6 1 8
j = 0 2 5 1 6 8
j = 1 2 5 1 6 8
j = 0 2 1 5 6 8
Sorted Array: 1 2 5 6 8
First Pass
i = 1
Second Pass
i = 2
Third Pass
i = 3
Fourth Pass
i = 1
ALGORITHM
void bubble_sort( int a[ ] , int n)
{
int I, j, temp;
for (i = 1 ; i < n ; i++)
for (j = i - 1 ; j <= n - i ; j++)
if(a[j] > a[j + 1])
{
temp = a[i];
a[j + 1] = a[j];
a[j] = temp;
}
}
SELECTION SORT
• Selection sort is a very simple sorting method. In the ith pass, we select the element with the
lowest value amongst a[i], a[i + 1],…,a[n – 1] and we swap it with a[i]. As a result, after i passes
first element will be in sorted order.
5 9 1 11 2 4 Original Array
1 9 5 11 2 4 After First Pass
1 2 5 11 9 4 After Second Pass
1 2 4 11 9 5 After Third Pass
1 2 4 5 9 11 After Fourth Pass
1 2 4 5 9 11 After Fifth Pass
ALGORITHM
void _sort( int a[ ] , int n)
{
int i, j, temp;
for (i = 0 ; i < n - 1 ; i++)
{
k = i;
for (j = i + 1 ; j < n ; j++)
if(a[j] < a[k])
k = j;
if ( k != i )
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}
Quick Sort
• Quick sort is the fastest internal sorting algorithm.
5 1 2 9 0 8 13
5 1 2 9 0 8 13
1 2 0
1 2 0
9 8 13
9 8 13
5
0
1
2 8
9
13
0 1 2 5 8 9 13
ALGORITHM
void _sort( int a[ ] , int n)
{
int i, j, temp;
for (i = 0 ; i < n - 1 ; i++)
{
k = i;
for (j = i + 1 ; j < n ; j++)
if(a[j] < a[k])
k = j;
if ( k != i )
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}

More Related Content

What's hot

Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
Rafay Farooq
 

What's hot (20)

Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
stack & queue
stack & queuestack & queue
stack & queue
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
Unit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxUnit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptx
 
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...
 
Queues
QueuesQueues
Queues
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 

Viewers also liked

File organization techniques
File organization techniquesFile organization techniques
File organization techniques
Meghlal Khan
 
File Organization
File OrganizationFile Organization
File Organization
Manyi Man
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
guest084d20
 

Viewers also liked (20)

Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 
Aa sort-v4
Aa sort-v4Aa sort-v4
Aa sort-v4
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Concept of computer files for Grade 12 learners
Concept of computer files for Grade 12 learnersConcept of computer files for Grade 12 learners
Concept of computer files for Grade 12 learners
 
File organization techniques
File organization techniquesFile organization techniques
File organization techniques
 
BUCKET SORT
BUCKET SORTBUCKET SORT
BUCKET SORT
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision Algorithm
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
File organization
File organizationFile organization
File organization
 
File organization 1
File organization 1File organization 1
File organization 1
 
File organisation
File organisationFile organisation
File organisation
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
File structures
File structuresFile structures
File structures
 
File Organization
File OrganizationFile Organization
File Organization
 
Parallel sorting
Parallel sortingParallel sorting
Parallel sorting
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 
Parallel sorting Algorithms
Parallel  sorting AlgorithmsParallel  sorting Algorithms
Parallel sorting Algorithms
 
Parallel Algorithm Models
Parallel Algorithm ModelsParallel Algorithm Models
Parallel Algorithm Models
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithm
 

Similar to Different Sorting tecniques in Data Structure

MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptxMYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
ArjayBalberan1
 

Similar to Different Sorting tecniques in Data Structure (20)

sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
 
Chapter2.1 .pptx
Chapter2.1 .pptxChapter2.1 .pptx
Chapter2.1 .pptx
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Sorting Algorithms.
Sorting Algorithms.Sorting Algorithms.
Sorting Algorithms.
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
 
Sorting techniques
Sorting techniques Sorting techniques
Sorting techniques
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 
CSPC/ PPS Sorting methods
CSPC/ PPS Sorting methodsCSPC/ PPS Sorting methods
CSPC/ PPS Sorting methods
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
 
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptxMYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

Different Sorting tecniques in Data Structure

  • 1. BIRLA VISHVAKARMA MAHAVIDHYALAYA Sorting in DATA STRUCTURE Sr. No. Names Enrollment No. 1. Rudra Patel 140080116050 2. Rishab Shah 140080116054 3. Tushar Gonawala 140080116059 4. Rushang Patel 140080116064 PRESENTED TO: Prof. Vikram
  • 2. SORTING • Sorting is the process of ordering a list of elements in either ascending order or descending order. • Sorting can be divided into two categories: 1. Internal Sorting: takes place in the main memory of the computer. It can take advantage of the random access nature of the main memory. Element to be sorted is stored in an integer array. 2. External Sorting: is carried on secondary memory. It becomes a necessity if the number of elements to be sorted is too large to be fit in the main memory. Algorithm should always take into account that movement of data between secondary storage and main storage is best done by moving a block of contiguous element.
  • 3. INSERTION SORT • Insertion sort is based on the principle of inserting the element at its correct place in a previously sorted list. It can be varied from 1 to n-1 to sort the entire array. 1st Iteration 0 5 1 9 2 6 4 2nd Iteration 0 1 5 9 2 6 4 3rd Iteration 0 1 5 9 2 6 4 4th Iteration 0 1 2 5 9 6 4 5th Iteration 0 1 2 5 6 9 4 6th Iteration 0 1 2 4 5 9 6 Sorted Unsorted Sorted Sorted Sorted Sorted Sorted Unsorted Unsorted Unsorted Unsorted
  • 4. ALGORITHM void insertion_sort( int a[ ] , int n) { int I, j, temp; for (i = 1 ; i < n ; i++) { temp = a[i]; for (j = i - 1 ; j >= 0 && a[j] > temp ; j--) a[j + 1] = a[j]; a[j +1] = temp; } }
  • 5. BUBBLE SORT • Bubble sort is one of the simplest and the most popular sorting method. The basic idea behind bubble sort is as a bubble rises up in water, the smallest element goes to the beginning. This method is based on the successive selecting the smallest element through exchange of adjacent element. j = 0 5 6 2 8 1 j = 1 5 6 2 8 1 j = 2 5 2 6 8 1 j = 3 5 2 6 8 1 j = 0 5 2 6 1 8 j = 1 2 5 6 1 8 j = 2 2 5 6 1 8 j = 0 2 5 1 6 8 j = 1 2 5 1 6 8 j = 0 2 1 5 6 8 Sorted Array: 1 2 5 6 8 First Pass i = 1 Second Pass i = 2 Third Pass i = 3 Fourth Pass i = 1
  • 6. ALGORITHM void bubble_sort( int a[ ] , int n) { int I, j, temp; for (i = 1 ; i < n ; i++) for (j = i - 1 ; j <= n - i ; j++) if(a[j] > a[j + 1]) { temp = a[i]; a[j + 1] = a[j]; a[j] = temp; } }
  • 7. SELECTION SORT • Selection sort is a very simple sorting method. In the ith pass, we select the element with the lowest value amongst a[i], a[i + 1],…,a[n – 1] and we swap it with a[i]. As a result, after i passes first element will be in sorted order. 5 9 1 11 2 4 Original Array 1 9 5 11 2 4 After First Pass 1 2 5 11 9 4 After Second Pass 1 2 4 11 9 5 After Third Pass 1 2 4 5 9 11 After Fourth Pass 1 2 4 5 9 11 After Fifth Pass
  • 8. ALGORITHM void _sort( int a[ ] , int n) { int i, j, temp; for (i = 0 ; i < n - 1 ; i++) { k = i; for (j = i + 1 ; j < n ; j++) if(a[j] < a[k]) k = j; if ( k != i ) { temp = a[i]; a[i] = a[k]; a[k] = temp; } } }
  • 9. Quick Sort • Quick sort is the fastest internal sorting algorithm. 5 1 2 9 0 8 13 5 1 2 9 0 8 13 1 2 0 1 2 0 9 8 13 9 8 13 5 0 1 2 8 9 13 0 1 2 5 8 9 13
  • 10. ALGORITHM void _sort( int a[ ] , int n) { int i, j, temp; for (i = 0 ; i < n - 1 ; i++) { k = i; for (j = i + 1 ; j < n ; j++) if(a[j] < a[k]) k = j; if ( k != i ) { temp = a[i]; a[i] = a[k]; a[k] = temp; } } }