Sorting Algorithm Latex Presentation
Sorting Algorithm Latex Presentation
Welcome
Outline
5 Conclusion
1 Welcome
6 References
2 First Topic : Selection Sort
7 Questions & Answers
3 Second Topic :Insertion Sort
8 Thanks
4 Result Complexity Analysis
Selection Sort
For the first position in the sorted array, traverse the entire array.
Find the minimum value (11) and swap it with the element at the first
position (64).
64 25 12 22 11
↓
11 25 12 22 64
For the second position, find the second minimum value (12) and
swap it with the element at the second position (25).
11 25 12 22 64
↓
11 12 25 22 64
For the third position, find the third minimum value (22) and swap it
with the element at the third position (25).
11 12 25 22 64
↓
11 12 22 25 64
For the fourth position, find the fourth minimum value (25) and never
swap it.
11 12 22 25 64
↓
11 12 22 25 64
11 12 22 25 64
↓
11 12 22 25 64
6 if min_idx ̸= i then
7 Swap(arr [min_idx], arr [i]);
Insertion Sort
Insertion Sort
For each element, insert it into its correct position in the sorted
portion of the array.
Shift elements greater than the key to the right.
Repeat until the entire array is sorted.
Initially, the first two elements of the array are compared in insertion
sort.
Here, 23 is greater than 1 hence they are not in the ascending order
and 23 is not at its correct position. Thus, swap 1 and 23.
23 1 10 5 2
↓
1 23 10 5 2
Here, 23 is greater than 10 hence they are not in the ascending order
and 10 is not at its correct position. Thus, swap 1 and 23. 10 also
stored in a sorted sub-array along with 1
1 23 10 5 2
↓
1 10 23 5 2
1 10 23 5 2
↓
1 10 5 23 2
↓
1 5 10 23 2
1 5 10 23 2
↓
1 5 10 2 23
↓
1 5 2 10 23
↓
1 2 5 10 23
Md. Abu Sufyan Md. Tameem Rahman Partha Paul
Roll: 2003085 Roll: 2003089 Roll: 2003078
Department: CSE Department: CSE Department: CSE
Insertion and Selection Sort (Rajshahi University
January 20,
of Engineering
2024 17
& /Techn
27
Second Topic :Insertion Sort Insertion Sort Demonstration
arr[j + 1] = key;
}
}
Md. Abu Sufyan Md. Tameem Rahman Partha Paul
Roll: 2003085 Roll: 2003089 Roll: 2003078
Department: CSE Department: CSE Department: CSE
Insertion and Selection Sort (Rajshahi University
January 20,
of Engineering
2024 20
& /Techn
27
Result Complexity Analysis
Explanation:
As dataset size grows, both algorithms
exhibit expected quadratic time
complexity, leading to increased running
times.
Graph lines depict the upward trend,
showcasing the correlation between
runtime and input data size.
In smaller datasets, Insertion Sort may
outperform Selection Sort, but as data
size increases, Selection Sort may Figure: Complexity Graph.
surpass Insertion Sort in relative
efficiency.
Md. Abu Sufyan Md. Tameem Rahman Partha Paul
Roll: 2003085 Roll: 2003089 Roll: 2003078
Department: CSE Department: CSE Department: CSE
Insertion and Selection Sort (Rajshahi University
January 20,
of Engineering
2024 22
& /Techn
27
Result Complexity Analysis Sorting Algorithms - Time Complexity
Time Complexity:
Selection Sort: O(n²) - traverses unsorted part for each element.
Insertion Sort: O(n²) - iteratively compares for correct positioning.
Best-Case Scenario:
Selection Sort: O(n²) - traverses entire unsorted part even with
partial sorting.
Insertion Sort: O(n) - when already sorted, compares with adjacent
elements for verification.
References
Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, and Clifford Stein.
Introduction to Algorithms.
MIT Press, 2022.
Fahriye Gemci.
A comparative study of selection sort and insertion sort algorithms.
International Research Journal of Engineering and Technology, 3(12):326–330, 2016.
Ellis Horowitz, Sartaj Sahni, and Sanguthevar Rajasekaran.
Computer Algorithms C++: C++ and Pseudocode Versions.
Macmillan, 1997.
Shivani Mittal.
Loop invariant condition examples in sorting algorithms, 2021.
Prep-Insta.
Selection sort in java.
Accessed on 2024-01-18.
Austin Stanley.
Insertion sort, 2021.
Md. Abu Sufyan Md. Tameem Rahman Partha Paul
Roll: 2003085 Roll: 2003089 Roll: 2003078
Department: CSE Department: CSE Department: CSE
Insertion and Selection Sort (Rajshahi University
January 20,
of Engineering
2024 25
& /Techn
27
Questions & Answers
Any Questions?
Thanks