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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is non-in-plave sorting?

A
  • Program requires extra space
  • More than or equal to the elements being sorted
  • MERGE SORT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the psudocode for bubble sort?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the psudocode for merge sort?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly