Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 102-insertion-sort.md #5591

Merged
merged 2 commits into from
May 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Insertion Sort

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It's much less efficient on large lists than more advanced algorithms like quicksort, heapsort, or merge sort. Still, it provides several advantages such as it's easy to understand the algorithm, it performs well with small lists or lists that are already partially sorted and it can sort the list as it receives it. The algorithm iterates, consuming one input element each repetition and growing a sorted output list. At each iteration, it removes one element from the input data, finds the location it belongs within the sorted list and inserts it there. It repeats until no input elements remain.
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It's much less efficient on large lists than more advanced algorithms like quicksort, heapsort, or merge sort. Still, it provides several advantages such as it's easy to understand the algorithm, it performs well with small lists or lists that are already partially sorted and it can sort the list as it receives it. The algorithm iterates, consuming one input element each repetition and growing a sorted output list. At each iteration, it removes one element from the input data, finds the location it belongs within the sorted list and inserts it there. It repeats until no input elements remain.
Advantages and Disadvantages of Insertion Sort

Advantages:

- Simple Implementation: Insertion sort has a simple implementation, making it easy to understand and implement.
- Efficient for Small Data Sets: It is efficient for small data sets and performs well with partially sorted lists.
- Adaptive: It is efficient for nearly sorted data sets.

Disadvantages:

- Inefficiency with Large Data Sets: Insertion sort is significantly less efficient on large lists compared to more advanced algorithms like quicksort and merge sort.
- Memory Usage: Certain implementations of insertion sort may require more memory than more efficient algorithms such as quicksort or merge sort.
- Affected by Initial Order: The speed of insertion sort can be affected by the initial order of the data set

https://www.w3schools.com/dsa/dsa_algo_insertionsort.php
kamranahmedse marked this conversation as resolved.
Show resolved Hide resolved