2.3.3 Sorting algorithms Flashcards

1
Q

What are the sorting algorithms you need to know?

A
  • Bubble sort
  • Insertion sort
  • Merge sort
  • Quick sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain bubble sort

A
  • Compares first pair of items
  • Swaps them if they arent in order
  • Compares next pair
  • After one pass, largest/smallest is guranteed to be in corrrect position
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the time and space complexities of bubble sort?

A
  • Time complexity: O(n^2)
  • Space complexity: O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is insertion sort?

A
  • Places elements into sorted sequence
  • Each iteration places one element into its correct position
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the time and space complexities for insertion sort?

A
  • Time complexity: O(n^2)
  • Space complexity: O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain merge sort

A
  • Divide and conquer
  • List is divided into parts until sublists of length 1 are obtained
  • Sublists are grouped back together
  • Final group is sorted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the time and space complexities of merge sort?

A
  • Time complexity: O(n log n)
  • Space complexity: O(n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain quick sort

A
  • Select middle element as pivot
  • Place elements smaller than the pivot to its left and elements larger to its right
  • Select pivot from each sublist
  • Repeat until every item has been selected as a pivot
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the time and space complexities for quick sort?

A
  • Time complexity: O(n^2)
  • Space complexity: O(log n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly