sorting-algorithms-flashcards
What is Selection Sort’s time complexity (best and worst case)?
O(n²) for both best and worst case - always needs to scan entire array multiple times
How does Selection Sort work?
Find minimum element in unsorted portion, swap it with first unsorted position, repeat
What are Selection Sort’s main advantages?
Simple to implement, performs well on small arrays, minimal memory usage (in-place)
What are Selection Sort’s main disadvantages?
Slow for large datasets, doesn’t adapt to partially sorted arrays, always O(n²)
What is Bubble Sort’s time complexity (best and worst case)?
Best case O(n) when already sorted, worst case O(n²)
How does Bubble Sort work?
Repeatedly step through the list, compare adjacent elements and swap if needed, until no swaps needed
What are Bubble Sort’s main advantages?
Simple to implement, best case O(n) on nearly sorted data, detects when array is sorted
What are Bubble Sort’s main disadvantages?
Very inefficient for large unsorted arrays, many swap operations, poor cache performance
What is Insertion Sort’s time complexity (best and worst case)?
Best case O(n) when nearly sorted, worst case O(n²)
How does Insertion Sort work?
Build sorted array one item at a time, insert each element into its correct position in sorted portion
What are Insertion Sort’s main advantages?
Efficient for small data, great for nearly sorted data, adaptive algorithm, in-place sorting
What are Insertion Sort’s main disadvantages?
Inefficient for large unsorted datasets, requires shifting elements during insertion
What is Merge Sort’s time complexity (best and worst case)?
O(n log n) for both best and worst case - consistently efficient
How does Merge Sort work?
Divide array into halves, sort recursively, merge sorted halves back together
What are Merge Sort’s main advantages?
Stable sort, guaranteed O(n log n), great for linked lists, predictable performance