SlideShare a Scribd company logo
MR. GOVERDHAN SATISH K.V
PGT CS
KV AFS , YELAHANKA
BANGALORE REGIONMR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
ACTIVITY – Assembly
I request 4 friends to come on dice and stand
besides each other in height wise.
I call upon 2 more friends to come.
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
INSERTIONSORT
BUBBLE SORT
The basic idea of bubble sort is to compare
two adjoining values and exchange them if
they are not in proper order.
EXAMPLE- the following unsorted array is to
be sorted in ascending order using bubble
sort.
1
4
2
5
5
1
8
3
1
4
5
2
5
1
8
3
No
Change
SWAP
1
4
2
5
5
1
8
3
SWAP
1
4
5
1
8
2
5
3
SWAP
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
3 5 14 18 25
5 3 14 18 25
SWA
P
SORTED
ARRAY
No
Change
No
Change
No
Change
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
SELECTIONSORT
• Its basic idea is to repeatedly select
the smallest key and place in
order.
• Example- The following array is to be sorted in
ascending order using selection sort.
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
16 7 14 23 4 53 3
3 7 14 23 4 53 16
Smalles
t
Interchange the
Element
Smallest
Interchange the
Element
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
3 4 14 23 7 53 16
3 4 7 23 14 53 16
SmallestInterchange the
Element
Interchange the
Element Smallest
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
3 4 7 14 23 53 16
3 4 7 14 16 53 23
Smallest
Smallest
Interchange the
Element
Interchange the
Element LARGES
T
THE ARRAY IS SORTED IN ASCENDING ORDER USING SELECTION
SORT
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
SORTED ARRAY
3 4 7 14 16 23 53
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
INSERTION SORT
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
OBJECTIVE
• Understand how insertion sort works.
• Mastering nested loops
• Reasoning ability
• Mastering 1D array(modify,insert)
• Conceptualizing to real world
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
Insertion Sort Start with a sorted list of 1 element
on the left, and N-1 unsorted items on the right.
Take the first unsorted item (element #2) and insert
it into the sorted list, moving elements as
necessary.
We now have a sorted list of size 2, and N -2
unsorted elements. Repeat for all elements.
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
Example- Lets enter some random elements.
1
1
215
3
5
4
Now lets try to sort array is using insertion sort.
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
1
1
215
3
5
4
5 21
1
1
3
5
4
As 5 is smaller than 11. the element 5 is
to be inserted before 11Therefore it
moves to the left.
5
4
As 4 is smaller than 5 and 11.
Therefore the element 4 is to be inserted
before 5.
5
4
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
4 215
3
5
1
1
1 2
1
1
4
3
5
5
As 1 is smaller than 10,5, and 4.
Therefore it is inserted before the
element 4.
As 35 is greater than 10 , the first
element to the left . No change in the
list happens. Therefore it maintains
its position.
1
1
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
3
5
1 2
1
1
4
3
5
5
As 2 is smaller than 35, 10, 5, and 4, but greater than 1. Therefore the
element 2 is inserted between 4 and 1.
.
2
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
SORTED ARRAY
1
1
1
52
3
5
4
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
IMPLEMENTATI
ON
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
1 2
1
1
4
3
5
5
As 2 is smaller than 35, 10, 5, and 4, but greater than 1.
Therefore the element 2 is to be inserted between 4 and 1.
2
0 1 2 3 4 5
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
How to insert the element 2 into
sorted listkey = a[5];
for(j = 4 ;j>=0; j--)
{
if(key < a[j])
a[j+1] = a[j]
else
break;
}
a[j+1] = key;MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
Insertion sort - function
void insertion_sort(int a[100], int n)
{
for(int i = 1; i<n; i++ )
{
key = a[i];
for(int j=i-1 ; j>=0; j--)
{
if(key < a[j])
a[j+1] = a[j]
else
break;
}
a[j+1] = key;
display(a,n);
}
}
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
Questionnaire
• Name any two applications of insertion sort.
• Is there any other way we can implement
insertion sort.
MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
MR. GOVERDHAN SATISH K.V, PGT CS, KV
AFS, YELAHANKA , BANGALORE

More Related Content

PPT
Present simple and continuous
PPT
Ch 6 collecting your data
PPT
Presentation by Escola d'Hoteleria i Turisme de Barcelona at the Study Visit ...
ODP
Building Community
PPT
Downturn Management
PPTX
An Explanation of Domain Names
PDF
Archi. REham hamed_C.V
PDF
Madina book 1 arabic solutions
Present simple and continuous
Ch 6 collecting your data
Presentation by Escola d'Hoteleria i Turisme de Barcelona at the Study Visit ...
Building Community
Downturn Management
An Explanation of Domain Names
Archi. REham hamed_C.V
Madina book 1 arabic solutions

Viewers also liked (14)

PPT
Tartalomszolgáltatás a könyvtári honlapokon (Papp József)
PPT
Chuck and larry
PPTX
Arystanbekova ainur portal_svadbnyx_uslug
PDF
札幌Ibmクラウド勉強会 blockchain
PPT
Smiling @ Friends
PPTX
Hume Discover - Adam Hornsey
PPT
Leadership Learning Community Board Report
PDF
INFIN8VENTURES - Digital Agency Presentation
PPTX
Psychiatric hospital fire
DOCX
Colegio nacional nicolás esguerra
PPTX
Introduction to computer
PDF
Lampiran b-sni-6989.59.2008a
PPT
Buatava reunion 2013
PPT
20091210 Sectorplan Vmbo Presentatie
Tartalomszolgáltatás a könyvtári honlapokon (Papp József)
Chuck and larry
Arystanbekova ainur portal_svadbnyx_uslug
札幌Ibmクラウド勉強会 blockchain
Smiling @ Friends
Hume Discover - Adam Hornsey
Leadership Learning Community Board Report
INFIN8VENTURES - Digital Agency Presentation
Psychiatric hospital fire
Colegio nacional nicolás esguerra
Introduction to computer
Lampiran b-sni-6989.59.2008a
Buatava reunion 2013
20091210 Sectorplan Vmbo Presentatie
Ad

More from Dipayan Sarkar (18)

PPT
Relationships
PPTX
ideal learning space
PPTX
introduction to aep arc
PPTX
why focus on adolescents unique needs
PPT
aep in india milestones, learning, way forward
PDF
Softskills - S Fernandez
PDF
Project Based Learning- Ashish K Chaurdia
PDF
Linux and the Open Source- D Sarkar
PPT
File Handling - N K Upadhyay
PPTX
Application of Stack - Yadraj Meena
PPT
Information Technology Act 2000 - Santosh K Pathak
PPTX
Universal Gates - Aneesa N Ali
PPT
Selection Sort - Vipin Ramola
PPT
Deletion of a Record from a File - K Karun
PPTX
Java Databse Connectvity- Alex Jose
PPTX
Computer Viruses- B S Kalyan Chakravarthy
PPT
Cloud Computing- Sreehari S
PPTX
SQL JOINS- Reena P V
Relationships
ideal learning space
introduction to aep arc
why focus on adolescents unique needs
aep in india milestones, learning, way forward
Softskills - S Fernandez
Project Based Learning- Ashish K Chaurdia
Linux and the Open Source- D Sarkar
File Handling - N K Upadhyay
Application of Stack - Yadraj Meena
Information Technology Act 2000 - Santosh K Pathak
Universal Gates - Aneesa N Ali
Selection Sort - Vipin Ramola
Deletion of a Record from a File - K Karun
Java Databse Connectvity- Alex Jose
Computer Viruses- B S Kalyan Chakravarthy
Cloud Computing- Sreehari S
SQL JOINS- Reena P V
Ad

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Classroom Observation Tools for Teachers
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Presentation on HIE in infants and its manifestations
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Complications of Minimal Access Surgery at WLH
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
Classroom Observation Tools for Teachers
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Presentation on HIE in infants and its manifestations
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
human mycosis Human fungal infections are called human mycosis..pptx
Computing-Curriculum for Schools in Ghana
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
A systematic review of self-coping strategies used by university students to ...
GDM (1) (1).pptx small presentation for students
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Complications of Minimal Access Surgery at WLH
VCE English Exam - Section C Student Revision Booklet
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial diseases, their pathogenesis and prophylaxis

Sorting Techniques - Govardhan Satish

  • 1. MR. GOVERDHAN SATISH K.V PGT CS KV AFS , YELAHANKA BANGALORE REGIONMR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 2. ACTIVITY – Assembly I request 4 friends to come on dice and stand besides each other in height wise. I call upon 2 more friends to come. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE INSERTIONSORT
  • 3. BUBBLE SORT The basic idea of bubble sort is to compare two adjoining values and exchange them if they are not in proper order. EXAMPLE- the following unsorted array is to be sorted in ascending order using bubble sort.
  • 5. 3 5 14 18 25 5 3 14 18 25 SWA P SORTED ARRAY No Change No Change No Change MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 6. SELECTIONSORT • Its basic idea is to repeatedly select the smallest key and place in order. • Example- The following array is to be sorted in ascending order using selection sort. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 7. 16 7 14 23 4 53 3 3 7 14 23 4 53 16 Smalles t Interchange the Element Smallest Interchange the Element MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 8. 3 4 14 23 7 53 16 3 4 7 23 14 53 16 SmallestInterchange the Element Interchange the Element Smallest MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 9. 3 4 7 14 23 53 16 3 4 7 14 16 53 23 Smallest Smallest Interchange the Element Interchange the Element LARGES T THE ARRAY IS SORTED IN ASCENDING ORDER USING SELECTION SORT MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 10. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE SORTED ARRAY 3 4 7 14 16 23 53 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 11. INSERTION SORT MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 12. OBJECTIVE • Understand how insertion sort works. • Mastering nested loops • Reasoning ability • Mastering 1D array(modify,insert) • Conceptualizing to real world MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 13. Insertion Sort Start with a sorted list of 1 element on the left, and N-1 unsorted items on the right. Take the first unsorted item (element #2) and insert it into the sorted list, moving elements as necessary. We now have a sorted list of size 2, and N -2 unsorted elements. Repeat for all elements. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 14. Example- Lets enter some random elements. 1 1 215 3 5 4 Now lets try to sort array is using insertion sort. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 15. 1 1 215 3 5 4 5 21 1 1 3 5 4 As 5 is smaller than 11. the element 5 is to be inserted before 11Therefore it moves to the left. 5 4 As 4 is smaller than 5 and 11. Therefore the element 4 is to be inserted before 5. 5 4 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 16. 4 215 3 5 1 1 1 2 1 1 4 3 5 5 As 1 is smaller than 10,5, and 4. Therefore it is inserted before the element 4. As 35 is greater than 10 , the first element to the left . No change in the list happens. Therefore it maintains its position. 1 1 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE 3 5
  • 17. 1 2 1 1 4 3 5 5 As 2 is smaller than 35, 10, 5, and 4, but greater than 1. Therefore the element 2 is inserted between 4 and 1. . 2 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 18. SORTED ARRAY 1 1 1 52 3 5 4 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 19. IMPLEMENTATI ON MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 20. 1 2 1 1 4 3 5 5 As 2 is smaller than 35, 10, 5, and 4, but greater than 1. Therefore the element 2 is to be inserted between 4 and 1. 2 0 1 2 3 4 5 MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 21. How to insert the element 2 into sorted listkey = a[5]; for(j = 4 ;j>=0; j--) { if(key < a[j]) a[j+1] = a[j] else break; } a[j+1] = key;MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 22. Insertion sort - function void insertion_sort(int a[100], int n) { for(int i = 1; i<n; i++ ) { key = a[i]; for(int j=i-1 ; j>=0; j--) { if(key < a[j]) a[j+1] = a[j] else break; } a[j+1] = key; display(a,n); } } MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 23. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 24. Questionnaire • Name any two applications of insertion sort. • Is there any other way we can implement insertion sort. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE
  • 25. MR. GOVERDHAN SATISH K.V, PGT CS, KV AFS, YELAHANKA , BANGALORE