Sort Algorithms Flashcards

1
Q

The key steps for Bubble Sort are:

A
  1. Iterate through each pair of elements (i, i+1)
  2. Compare them; swap them if not in the desired order
    (largest/smallest element should be at end of array after first iteration)
  3. Repeat for subsequent iterations, excluding the most recently sorted value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The key steps for Insertion Sort are:

A
  1. Assume the first element is sorted.
  2. Iterate through each subsequent element (in the unsorted subarray): this is the target.
  3. Determine the most appropriate place in sorted subarray to insert the target element
  4. Carry out the insertion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The key steps for Merge Sort are:

A
  1. Handle the base case (empty/single-element array)
  2. Split the array into left and right subarrays
  3. Recursively sort the left and right subarrays
  4. Merge left and right subarrays into sorted array

Merge function

  1. Initialise new array
  2. Compare first elements of left & right subarray.
  3. Pop the smaller/greater first element into array from (1); repeat from Step 2
  4. Concatenate remaining elements to the end of array from (1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The key steps for Quick Sort are:

A
  1. Handle the base case (empty/single-element array)
  2. Select pivot (can use last element)
  3. Initialise less-than (lt) and greater-than-equal (gte) subarrays
  4. Iterate through all elements except pivot; if element less than pivot, append to lt; if element greater than or equal pivot, append to gte.
  5. Recursively sort lt and gte
  6. Recombine lt, gte, and pivot into a single array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the time complexity for an Insertion Sort?

A

O(n²)

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

What is the time complexity for a Quick Sort?

A

O(n log n)

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

Under what circumstances is the quicksort least efficient?

A

When the provided list is nearly sorted or already sorted (pivot is not median value).

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

What does it mean when a sorting algorithm is said to be ‘stable’?

A

A stable sorting algorithm ensures that elements with identical sorting properties still maintain their original order.

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

What is the key determining factor that affects the execution time of a sort algorithm?

A

The size of the given array.

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

What is the time complexity for a Bubble Sort?

A

O(n²)

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

What is the time complexity for a Merge Sort?

A

O(n log n)

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