tangorishi / learnJava

LearnJava - Hacktoberfest 2023 πŸš€ Join us in celebrating Hacktoberfest 2023 by contributing to this Java programming repository! Whether you're a beginner or an expert, dive into Java, share your knowledge, and make Hacktoberfest unforgettable. πŸ“šπŸ’» Happy coding and contributing! πŸš€πŸŒŸ
MIT License
26 stars 45 forks source link

Create InsertionSort #111

Closed DevanshPaliwal closed 10 months ago

DevanshPaliwal commented 10 months ago

Description:

Insertion sort is a simple comparison-based sorting algorithm. It builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, it works well for small datasets or partially sorted data.

Changes Made:

Algorithm Modification: No significant changes are made to the original insertion sort algorithm, which typically involves iterating through the list and inserting each element into its correct position within the already sorted portion of the list.

Testing Done:

Input Data Testing: Insertion sort has been tested on a variety of input data, including both small and large datasets, as well as partially sorted and reverse-sorted lists.

Performance Testing: Its time complexity has been analyzed, especially for worst-case scenarios, to determine its limitations.

Stability Testing: Testing has been conducted to confirm that the algorithm is stable, meaning that it preserves the relative order of equal elements.

Additional Notes:

Insertion sort is an in-place sorting algorithm, which means it doesn't require additional memory for sorting. It's easy to implement and efficient for small lists or when the list is almost sorted.

In practice, insertion sort can be more efficient than other sorting algorithms for very small datasets due to its low constant factors.

While not suitable for large datasets, insertion sort can be used as part of more advanced sorting algorithms, which combines insertion sort and merge sort for better overall performance.

itsyourap commented 10 months ago

Duplicate (#50)