Sorting Algorithms Flashcards
Sorting definition (1)
1.) Arranging elements in a collection in increasing or decreasing order based on certain properties.
Why is sorting important (3)
- ) Some algorithms require sorted lists.
- ) To normalise and standardise data.
- ) To make searching easier.
Classification of sorting algorithms (4)
- ) Time complexity.
- ) Stability.
- ) Memory usage.
- ) Recursion
Bubble/Ripple sort (3)
- ) Brute force.
- ) Stable.
- ) In place.
Bubble/Ripple how (3)
- ) Compares adiacent elements in an array.
- ) If out of order swaps them, else go on.
- ) Continues until no swaps happen in one full pass.
Bubble/Ripple | Big O (2)
- ) Best: O(n)
2. ) Worst/Average: O( n^2 )
Merge sort (1)
1.) Divide and conquer.
Merge sort how (2)
- ) Divide list in n sub lists of 1 element.
2. ) Reunite sublists recursively, placing each element in the right order.
Merge | Big O (1)
1.) O( n log(n) )
Quicksort/Partition-Exchange sort (2)
- ) Divide and conquer
2. ) In-place
Quicksort how (5)
- ) Select a pivot.
- ) Scan array from two ends.
- ) From left, it looks for elements bigger than the pivot. From right it looks for elements smaller than the pivot.
- ) When it finds a element to swap it waits for the other side to find one and then swaps.
- ) Repeat step 1 until one element left in the list.
Quicksort Big O (2)
- ) Best/Average: O( n log(n) )
2. ) Worst: O ( n^2 )
Memory usage (1)
An algorithm is defined as in-place if it doesn’t require the creation of temporary memory spaces.
What is Stability (1)
A stable algorithm will maintain the original order of two entries with the same value of the property.