SlideShare a Scribd company logo
Sorting
Introduction
• Common problem: sort a list of values, starting
from lowest to highest.
– List of exam scores
– Words of dictionary in alphabetical order
– Students names listed alphabetically
– Student records sorted by ID#
• Generally, we are given a list of records that have
keys. These keys are used to define an ordering of
the items in the list.
Quadratic Sorting Algorithms
• We are given n records to sort.
• There are a number of simple sorting
algorithms whose worst and average case
performance is quadratic O(n2):
– Selection sort
– Insertion sort
– Bubble sort
Sorting an Array of Integers
• Example: we
are given an
array of six
integers that
we want to
sort from
smallest to
largest
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Start by
finding the
smallest
entry.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Swap the
smallest
entry with
the first
entry.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Swap the
smallest
entry with
the first
entry.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Part of the
array is now
sorted.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Find the
smallest
element in
the unsorted
side.
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• Swap with
the front of
the unsorted
side.
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• We have
increased the
size of the
sorted side
by one
element.
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• The process
continues...
Sorted side Unsorted side
Smallest
from
unsorted
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• The process
continues...
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• The process
continues...
Sorted side Unsorted side
Sorted side
is bigger
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• The process
keeps adding
one more
number to the
sorted side.
• The sorted side
has the smallest
numbers,
arranged from
small to large.
Sorted side Unsorted side
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• We can stop
when the
unsorted side
has just one
number, since
that number
must be the
largest number.
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted sid
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Selection Sort Algorithm
• The array is
now sorted.
• We repeatedly
selected the
smallest
element, and
moved this
element to the
front of the
unsorted side. [0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
• The Insertion
Sort algorithm
also views the
array as having
a sorted side
and an
unsorted side.
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
• The sorted
side starts
with just the
first
element,
which is not
necessarily
the smallest
element.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
• The sorted
side grows
by taking the
front
element
from the
unsorted
side... 0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
• ...and
inserting it
in the place
that keeps
the sorted
side
arranged
from small
to large.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertion Sort Algorithm
• Sometimes
we are lucky
and the new
inserted item
doesn't need
to move at
all.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Insertionsort Algorithm
• Sometimes
we are lucky
twice in a
row.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Copy the
new element
to a separate
location.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
Sorted side Unsorted side
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Shift
elements in
the sorted
side,
creating an
open space
for the new
element.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Shift
elements in
the sorted
side,
creating an
open space
for the new
element.
[3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Continue
shifting
elements...
[3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Continue
shifting
elements...
[3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
...until you
reach the
location for
the new
element.
[3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
Copy the
new element
back into the
array, at the
correct
location.
[3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
Sorted side Unsorted sid
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
How to Insert One Element
[2] [3] [4] [5] [6]
• The last
element
must also be
inserted.
Start by
copying it...
[0] [1] [2] [3] [4] [5]
Sorted side Unsorted sid
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted Result
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Swap?
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Yes!
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Swap?
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Swap?
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Swap?
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Yes!
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Swap?
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• The Bubble
Sort algorithm
looks at pairs
of entries in
the array, and
swaps their
order if
needed.
[0] [1] [2] [3] [4] [5]
Yes!
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Repeat.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? Yes.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Loop over
array n-1
times,
swapping pairs
of entries as
needed.
[0] [1] [2] [3] [4] [5]
Swap? No.
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
The Bubble Sort Algorithm
• Continue
looping, until
done.
[0] [1] [2] [3] [4] [5]
Swap? Yes.

More Related Content

PPTX
Sorting Algorithms
PPT
DSSchapt13.ppt
PPTX
Data Structures_Searching and Sorting.pptx
PPT
Sorting
PPTX
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
PPTX
9.Sorting & Searching
PPTX
Sorting Algorithms to arrange data in particular format
PPTX
Different Searching and Sorting Methods.pptx
Sorting Algorithms
DSSchapt13.ppt
Data Structures_Searching and Sorting.pptx
Sorting
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
9.Sorting & Searching
Sorting Algorithms to arrange data in particular format
Different Searching and Sorting Methods.pptx

Similar to Sorting of linked list data through python.ppt (20)

DOCX
Sorting
PPTX
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
PPT
Sorting Techniques
PDF
Quick sort,bubble sort,heap sort and merge sort
PPTX
Dsa – data structure and algorithms sorting
PPTX
Unit 5 dsuc
PDF
L 14-ct1120
PPTX
sorting algorithm graphical method
PDF
Algorithms Analysis
PPTX
All Searching and Sorting Techniques in Data Structures
PPTX
Searching,sorting
PPTX
Sorting-Algorithms-A-Comprehensive-Guide.pptx
PPTX
Sorting Algorithms
PPTX
SORTING techniques.pptx
PDF
Comparative Performance Analysis & Complexity of Different Sorting Algorithm
PPTX
Data structure.pptx
PPTX
Chapter 8 Sorting in the context of DSA.pptx
PDF
Sorting algorithms
PDF
Analysis and Comparative of Sorting Algorithms
PPTX
sorting-160810203705.pptx
Sorting
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
Sorting Techniques
Quick sort,bubble sort,heap sort and merge sort
Dsa – data structure and algorithms sorting
Unit 5 dsuc
L 14-ct1120
sorting algorithm graphical method
Algorithms Analysis
All Searching and Sorting Techniques in Data Structures
Searching,sorting
Sorting-Algorithms-A-Comprehensive-Guide.pptx
Sorting Algorithms
SORTING techniques.pptx
Comparative Performance Analysis & Complexity of Different Sorting Algorithm
Data structure.pptx
Chapter 8 Sorting in the context of DSA.pptx
Sorting algorithms
Analysis and Comparative of Sorting Algorithms
sorting-160810203705.pptx
Ad

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
English Language Teaching from Post-.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Pre independence Education in Inndia.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Week 4 Term 3 Study Techniques revisited.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
UPPER GASTRO INTESTINAL DISORDER.docx
English Language Teaching from Post-.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Pre independence Education in Inndia.pdf
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Module 3: Health Systems Tutorial Slides S2 2025
Open Quiz Monsoon Mind Game Final Set.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
How to Manage Starshipit in Odoo 18 - Odoo Slides
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Open folder Downloads.pdf yes yes ges yes
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Ad

Sorting of linked list data through python.ppt

  • 2. Introduction • Common problem: sort a list of values, starting from lowest to highest. – List of exam scores – Words of dictionary in alphabetical order – Students names listed alphabetically – Student records sorted by ID# • Generally, we are given a list of records that have keys. These keys are used to define an ordering of the items in the list.
  • 3. Quadratic Sorting Algorithms • We are given n records to sort. • There are a number of simple sorting algorithms whose worst and average case performance is quadratic O(n2): – Selection sort – Insertion sort – Bubble sort
  • 4. Sorting an Array of Integers • Example: we are given an array of six integers that we want to sort from smallest to largest 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 5. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Start by finding the smallest entry. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 6. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Swap the smallest entry with the first entry. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 7. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Swap the smallest entry with the first entry. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 8. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Part of the array is now sorted. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 9. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Find the smallest element in the unsorted side. Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 10. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • Swap with the front of the unsorted side. Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 11. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • We have increased the size of the sorted side by one element. Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 12. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • The process continues... Sorted side Unsorted side Smallest from unsorted [0] [1] [2] [3] [4] [5]
  • 13. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • The process continues... Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 14. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • The process continues... Sorted side Unsorted side Sorted side is bigger [0] [1] [2] [3] [4] [5]
  • 15. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • The process keeps adding one more number to the sorted side. • The sorted side has the smallest numbers, arranged from small to large. Sorted side Unsorted side [0] [1] [2] [3] [4] [5]
  • 16. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • We can stop when the unsorted side has just one number, since that number must be the largest number. [0] [1] [2] [3] [4] [5] Sorted side Unsorted sid
  • 17. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Selection Sort Algorithm • The array is now sorted. • We repeatedly selected the smallest element, and moved this element to the front of the unsorted side. [0] [1] [2] [3] [4] [5]
  • 18. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm • The Insertion Sort algorithm also views the array as having a sorted side and an unsorted side. [0] [1] [2] [3] [4] [5]
  • 19. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm • The sorted side starts with just the first element, which is not necessarily the smallest element. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 20. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm • The sorted side grows by taking the front element from the unsorted side... 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 21. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm • ...and inserting it in the place that keeps the sorted side arranged from small to large. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 22. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 23. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertion Sort Algorithm • Sometimes we are lucky and the new inserted item doesn't need to move at all. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 24. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Insertionsort Algorithm • Sometimes we are lucky twice in a row. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 25. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Copy the new element to a separate location. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted side
  • 26. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Shift elements in the sorted side, creating an open space for the new element. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 27. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Shift elements in the sorted side, creating an open space for the new element. [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 28. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Continue shifting elements... [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 29. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Continue shifting elements... [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 30. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element ...until you reach the location for the new element. [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] [0] [1] [2] [3] [4] [5]
  • 31. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element Copy the new element back into the array, at the correct location. [3] [4] [5] [6] [0] [1] [2] [3] [4] [5] Sorted side Unsorted sid
  • 32. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] How to Insert One Element [2] [3] [4] [5] [6] • The last element must also be inserted. Start by copying it... [0] [1] [2] [3] [4] [5] Sorted side Unsorted sid
  • 33. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted Result [0] [1] [2] [3] [4] [5]
  • 34. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5]
  • 35. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Swap?
  • 36. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Yes!
  • 37. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Swap?
  • 38. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] No.
  • 39. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Swap?
  • 40. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] No.
  • 41. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Swap?
  • 42. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Yes!
  • 43. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Swap?
  • 44. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • The Bubble Sort algorithm looks at pairs of entries in the array, and swaps their order if needed. [0] [1] [2] [3] [4] [5] Yes!
  • 45. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? No.
  • 46. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? No.
  • 47. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 48. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 49. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 50. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 51. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Repeat. [0] [1] [2] [3] [4] [5] Swap? No.
  • 52. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? No.
  • 53. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 54. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 55. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 56. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? Yes.
  • 57. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? No.
  • 58. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Loop over array n-1 times, swapping pairs of entries as needed. [0] [1] [2] [3] [4] [5] Swap? No.
  • 59. 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] The Bubble Sort Algorithm • Continue looping, until done. [0] [1] [2] [3] [4] [5] Swap? Yes.

Editor's Notes

  • #5: The picture shows a graphical representation of an array which we will sort so that the smallest element ends up at the front, and the other elements increase to the largest at the end. The bar graph indicates the values which are in the array before sorting--for example the first element of the array contains the integer 45.
  • #6: The first sorting algorithm that we'll examine is called Selectionsort. It begins by going through the entire array and finding the smallest element. In this example, the smallest element is the number 8 at location [4] of the array.
  • #7: Once we have found the smallest element, that element is swapped with the first element of the array...
  • #8: ...like this. The smallest element is now at the front of the array, and we have taken one small step toward producing a sorted array.
  • #9: At this point, we can view the array as being split into two sides: To the left of the dotted line is the "sorted side", and to the right of the dotted line is the "unsorted side". Our goal is to push the dotted line forward, increasing the number of elements in the sorted side, until the entire array is sorted.
  • #10: Each step of the Selectionsort works by finding the smallest element in the unsorted side. At this point, we would find the number 15 at location [5] in the unsorted side.
  • #11: This small element is swapped with the number at the front of the unsorted side, as shown here...
  • #12: ...and the effect is to increase the size of the sorted side by one element. As you can see, the sorted side always contains the smallest numbers, and those numbers are sorted from small to large. The unsorted side contains the rest of the numbers, and those numbers are in no particular order.
  • #13: Again, we find the smallest entry in the unsorted side...
  • #14: ...and swap this element with the front of the unsorted side.
  • #15: The sorted side now contains the three smallest elements of the array.
  • #16: Here is the array after increasing the sorted side to four elements.
  • #17: And now the sorted side has five elements. In fact, once the unsorted side is down to a single element, the sort is completed. At this point the 5 smallest elements are in the sorted side, and so the the one largest element is left in the unsorted side. We are done...
  • #18: ...The array is sorted. The basic algorithm is easy to state and also easy to program.
  • #19: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #20: ...like this. However, in the Selectionsort, the sorted side always contained the smallest elements of the array. In the Insertionsort, the sorted side will be sorted from small to large, but the elements in the sorted side will not necessarily be the smallest entries of the array. Because the sorted side does not need to have the smallest entries, we can start by placing one element in the sorted side--we don't need to worry about sorting just one element. But we do need to worry about how to increase the number of elements that are in the sorted side.
  • #21: The basic approach is to take the front element from the unsorted side...
  • #22: ...and insert this element at the correct spot of the sorted side. In this example, the front element of the unsorted side is 20. So the 20 must be inserted before the number 45 which is already in the sorted side.
  • #23: After the insertion, the sorted side contains two elements. These two elements are in order from small to large, although they are not the smallest elements in the array.
  • #24: Sometimes we are lucky and the newly inserted element is already in the right spot. This happens if the new element is larger than anything that's already in the array.
  • #25: Sometimes we are lucky twice in a row.
  • #26: The actual insertion process requires a bit of work that is shown here. The first step of the insertion is to make a copy of the new element. Usually this copy is stored in a local variable. It just sits off to the side, ready for us to use whenever we need it.
  • #27: After we have safely made a copy of the new element, we start shifting elements from the end of the sorted side. These elements are shifted rightward, to create an "empty spot" for our new element to be placed. In this example we take the last element of the sorted side and shift it rightward one spot...
  • #28: ...like this. Is this the correct spot for the new element? No, because the new element is smaller than the next element in the sorted section. So we continue shifting elements rightward...
  • #29: This is still not the correct spot for our new element, so we shift again...
  • #30: ...and shift one more time...
  • #31: Finally, this is the correct location for the new element. In general there are two situations that indicate the "correct location" has been found: 1. We reach the front of the array (as happened here), or 2. We reached an element that is less than or equal to the new element.
  • #32: Once the correct spot is found, we copy the new element back into the array. The number of elements in the sorted side has increased by one.
  • #33: The last element of the array also needs to be inserted. Start by copying it to a safe location.
  • #34: The new element is inserted into the array.
  • #35: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #36: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #37: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #38: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #39: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #40: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #41: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #42: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #43: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #44: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #45: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #46: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #47: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #48: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #49: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #50: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #51: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #52: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #53: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #54: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #55: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #56: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #57: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #58: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #59: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...
  • #60: Now we'll look at another sorting method called Insertionsort. The end result will be the same: The array will be sorted from smallest to largest. But the sorting method is different. However, there are some common features. As with the Selectionsort, the Insertionsort algorithm also views the array as having a sorted side and an unsorted side, ...