Sorting Algorithms Flashcards
1
Q
What is sorting?
A
- Determines how the data should be arranged in a specific order
- Taking an unordered collection and making it an ordered one
- Important due to
- Optimised data searching to a high level
- Readable data
- Dictionary + music tracks
2
Q
What is in place sorting?
A
- Program does not require any extra space
- May store temp elements
- Sorting happens in the data structure in itself
- BUBBLE SORT
3
Q
What is non-in-plave sorting?
A
- Program requires extra space
- More than or equal to the elements being sorted
- MERGE SORT
4
Q
What is bubble sort?
A
- Compares adjacent array elements
- Exchanging out of order values
- Larger values bubble up to the top of the array
- Smaller values sink to the bottom
- Keeps repeating until sorted
- $O(n^2)$ - SHIT TIME COMPLEXITY
5
Q
What is the psudocode for bubble sort?
A
6
Q
What is refined bubble sort?
A
- Checks if there is a need to sort
- Bubble up is less
- Allows for range of time complexity
7
Q
What is Merge Sort?
A
- Divide and conquer algorithm
- Keep halving until sub array only contains one element
- Merge sub problem solutions together
- Compare
- Remove smallest element
- Put into result array
- Continue until result array is completed
8
Q
What is the psudocode for merge sort?
A