3.1.4 - Sorting algorithms Flashcards
(8 cards)
Bubble sort
A bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This process continues until the list is sorted
Merge sort
A merge sort divides the list into halves, repeatedly sorts each half, and then merges the sorted halves back together to form a sorted list.
What are the advantages of a bubble sort?
Simple to understand and implement
Does not require additional memory
What are the disadvantages of a bubble sort?
Inefficient for large lists
Inefficient (slow) for large, unsorted datasets
What are the advantages of a merge sort?
Efficient (fast) for large, sorted lists
What are the disadvantages of a merge sort?
More complex to implement
Requires additional memory for the temporary arrays
When is a bubble sort more appropriate than a merge sort?
When working with small or nearly sorted datasets
Better for simpler datasets
When is a merge sort more appropriate than a bubble sort?
When dealing with large datasets where efficiency is crucial.