Professional Documents
Culture Documents
Insertion Sort
Insertion Sort
GROUP 1
INTRODUCTION
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
INSERTION SORT
Insertion sort is a simple sorting algorithm that works by
comparing each element in an array to the elements that
come before it, and inserting it into the correct position in
the sorted portion of the array. It is an iterative algorithm
that builds the final sorted array one item at a time.
Insertion Sort is not the most efficient algorithm for large
datasets, but it works well for small datasets or nearly
sorted datasets.
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
• Take the third element and compare it with the elements on the left of it.
Insert the element in its correct position among the sorted array.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
• Take the third element and compare it with the elements on the left of it.
Insert the element in its correct position among the sorted array.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
• Take the third element and compare it with the elements on the left of it.
Insert the element in its correct position among the sorted array.
• Repeat step 3 for all the remaining elements of the unsorted array.
unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
STEPS
• The first element of the unsorted array is considered as sorted.
• Take the second element and compare it with the first element. If
the second element is smaller than the first element, swap them.
• Take the third element and compare it with the elements on the left of it.
Insert the element in its correct position among the sorted array.
• Repeat step 3 for all the remaining elements of the unsorted array. unsorted
sorted
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
Efficient for Small Datasets: Performs well when dealing with partially ordered or small datasets,
as it minimizes unnecessary comparisons and swaps.
INTRODUCTION HOW INSERTION SORT WORKS ADVANTAGES & DISADVANTAGES INTRODUCTION
Inefficiency for Large Datasets: Its time complexity of O(n^2) can lead to inefficiency with larger
datasets, making it less suitable for such scenarios.
Not Suitable for Real-time Applications: In real-time applications where quick response times are essential, Insertion