2.3.3 - Sorting Algorithms Flashcards
What is the purpose of a sorting algorithm?
They are designed to take a number of elements in any order and output them in a logical order.
What are the four sorting algorithms?
Bubble sort
Insertion sort
Merge sort
Quick sort
How does a bubble sort work?
A bubble sort makes comparisons and swaps between pairs of elements.
What is the time complexity of the bubble sort algorithm?
O (n2).
How does an insertion sort work?
The insertion sort places elements into a sorted sequence.
What is the time complexity of an insertion sort?
O (n2).
How does a merge sort work?
A merge sort splits the data into lists of size one and then merges them together in order. It is a divide and conquer algorithm.
What is the time complexity of a merge sort algorithm?
O (n log n)
How does a quick sort work?
A quick sort works by selecting a pivot and sorting the list by comparing it to the pivot.
What is the time complexity of the quick sort algorithm?
O (n2).