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

PDF
Binary search tree operations
PPTX
PPTX
Ppt bubble sort
PDF
Trie Data Structure
PPT
1.5 binary search tree
PPTX
Binary Tree in Data Structure
PPTX
Introduction to data structure ppt
PPTX
Insertion sort
Binary search tree operations
Ppt bubble sort
Trie Data Structure
1.5 binary search tree
Binary Tree in Data Structure
Introduction to data structure ppt
Insertion sort

What's hot (20)

PPTX
Linked List
PDF
Algorithms Lecture 5: Sorting Algorithms II
PPTX
Linked List
PPTX
Binary Search Tree
PDF
Sorting Algorithms
PDF
Quick Sort , Merge Sort , Heap Sort
PPTX
sorting and its types
PDF
Searching and Sorting Techniques in Data Structure
PPTX
trees in data structure
PPTX
Quick sort
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
PPTX
Doubly linked list (animated)
PPT
Binary search trees
PPSX
Data Structure (Queue)
PPSX
Data structure stack&queue basics
PPTX
Merge sort
PPTX
single linked list
PPTX
Trees (data structure)
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
PPT
BINARY TREE REPRESENTATION.ppt
Linked List
Algorithms Lecture 5: Sorting Algorithms II
Linked List
Binary Search Tree
Sorting Algorithms
Quick Sort , Merge Sort , Heap Sort
sorting and its types
Searching and Sorting Techniques in Data Structure
trees in data structure
Quick sort
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Doubly linked list (animated)
Binary search trees
Data Structure (Queue)
Data structure stack&queue basics
Merge sort
single linked list
Trees (data structure)
Data Structures - Lecture 8 [Sorting Algorithms]
BINARY TREE REPRESENTATION.ppt
Ad

Viewers also liked (20)

PPTX
Sorting Algorithm
PPT
PPTX
PDF
File Organization & processing Mid term summer 2014 - modelanswer
PPTX
Concept of computer files for Grade 12 learners
PPT
File organization techniques
PPTX
BUCKET SORT
PPTX
Bucket sort- A Noncomparision Algorithm
PPTX
Sorting Algorithms
PPT
File organization
PPT
File organization 1
PPT
File organisation
PDF
Parallel Algorithms
PPT
File structures
PPTX
File Organization
PPTX
Parallel sorting
PPT
Parallel algorithms
PDF
Parallel sorting Algorithms
PPT
Parallel Algorithm Models
PPTX
Parallel sorting algorithm
Sorting Algorithm
File Organization & processing Mid term summer 2014 - modelanswer
Concept of computer files for Grade 12 learners
File organization techniques
BUCKET SORT
Bucket sort- A Noncomparision Algorithm
Sorting Algorithms
File organization
File organization 1
File organisation
Parallel Algorithms
File structures
File Organization
Parallel sorting
Parallel algorithms
Parallel sorting Algorithms
Parallel Algorithm Models
Parallel sorting algorithm
Ad

Similar to Different Sorting tecniques in Data Structure (20)

PPTX
sorting-160810203705.pptx
PPTX
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
PPT
Lecture_4 (Sorting Algorithms) before mids - Copy.ppt
PPT
Sorting Algorithms for data struture prog
PPT
Data Structure (MC501)
PPTX
Searching and sorting Techniques in Data structures
PPTX
Chapter2.1 .pptx
PPTX
Basic Sorting algorithms csharp
PPT
Sorting Algorithms.
PPT
Sorting
PPTX
A Comprehensive Comparative Study and Performance Evaluation
PDF
Sorting
PDF
Sorting
PPT
Decimal Long Double Double Double. Represents double-precision floating-point...
PPT
03_sorting123456789454545454545444543.ppt
PPT
03_sorting and it's types with example .ppt
PPT
quicksortnmsd cmz ,z m,zmm,mbfjjjjhjhfjsg
PDF
Sorting algorithms bubble sort to merge sort.pdf
PPT
Data Structures 6
PPT
Unit6 C
sorting-160810203705.pptx
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Lecture_4 (Sorting Algorithms) before mids - Copy.ppt
Sorting Algorithms for data struture prog
Data Structure (MC501)
Searching and sorting Techniques in Data structures
Chapter2.1 .pptx
Basic Sorting algorithms csharp
Sorting Algorithms.
Sorting
A Comprehensive Comparative Study and Performance Evaluation
Sorting
Sorting
Decimal Long Double Double Double. Represents double-precision floating-point...
03_sorting123456789454545454545444543.ppt
03_sorting and it's types with example .ppt
quicksortnmsd cmz ,z m,zmm,mbfjjjjhjhfjsg
Sorting algorithms bubble sort to merge sort.pdf
Data Structures 6
Unit6 C

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
Classroom Observation Tools for Teachers
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
Sports Quiz easy sports quiz sports quiz
PPH.pptx obstetrics and gynecology in nursing
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism
O7-L3 Supply Chain Operations - ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Classroom Observation Tools for Teachers
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study

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