SlideShare a Scribd company logo
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

Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
almaqboli
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation
AhmedAlbutty
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
sandeep54552
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
Edureka!
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
Ummar Hayat
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
asmhemu
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
Saurabh Mishra
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
Rojan Pariyar
 
Shell sorting
Shell sortingShell sorting
Shell sorting
TUC
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 

What's hot (20)

Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Quick sort
Quick sortQuick sort
Quick sort
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
single linked list
single linked listsingle linked list
single linked list
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary search
Binary searchBinary search
Binary search
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Shell sorting
Shell sortingShell sorting
Shell sorting
 
linked list
linked list linked list
linked list
 

Viewers also liked

Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
Al Amin
 
Bucket sort
Bucket sortBucket sort
Aa sort-v4
Aa sort-v4Aa 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
Arab Open University and Cairo University
 
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
wellingtonoboh
 
File organization techniques
File organization techniquesFile organization techniques
File organization techniquesMeghlal Khan
 
BUCKET SORT
BUCKET SORTBUCKET SORT
BUCKET SORT
eidyyolisbet
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision Algorithm
Krupali Mistry
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 
File structures
File structuresFile structures
File structures
Shyam Kumar
 
File Organization
File OrganizationFile Organization
File OrganizationManyi Man
 
Parallel sorting
Parallel sortingParallel sorting
Parallel sorting
Mr. Vikram Singh Slathia
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithmsguest084d20
 
Parallel sorting Algorithms
Parallel  sorting AlgorithmsParallel  sorting Algorithms
Parallel sorting Algorithms
GARIMA SHAKYA
 
Parallel Algorithm Models
Parallel Algorithm ModelsParallel Algorithm Models
Parallel Algorithm Models
Martin Coronel
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithm
Richa Kumari
 

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

sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
AnSHiKa187943
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
Kamal Singh Lodhi
 
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
PRIANKA R
 
Chapter2.1 .pptx
Chapter2.1 .pptxChapter2.1 .pptx
Chapter2.1 .pptx
RojaPogul1
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
Micheal Ogundero
 
Sorting Algorithms.
Sorting Algorithms.Sorting Algorithms.
Sorting Algorithms.
Saket Kumar
 
Sorting
SortingSorting
Sorting
Samsil Arefin
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
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...
Anwar Patel
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
Dr.Umadevi V
 
Sorting techniques
Sorting techniques Sorting techniques
Sorting techniques
JayeshGadhave1
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
chouguleamruta24
 
CSPC/ PPS Sorting methods
CSPC/ PPS Sorting methodsCSPC/ PPS Sorting methods
CSPC/ PPS Sorting methods
Ankur Srivastava
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
Shantanu Mishra
 
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
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
Abdullah Al-hazmy
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 

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 algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
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
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

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; } } }