Non - Comparison Sorting Algorithms Flashcards

1
Q

What are the 2 non-comparison sorting algorithms we have studied?

A
  • Counting sort

- Radix sort

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

What is the Big-Oh complexity of counting sort?

A

O(n)

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

Requirement of counting sort?

A

integers in the range of 0 to k. Where k is the size of the structure holding the counts.

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

Is counting sort stable?

A

Yes

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

Is counting sort in place?

A

No

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

What is the memory requirement of counting sort?

A

Linear O(n)

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

Is counting sort used within radix sort?

A

Yes

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

How does counting sort work?

A
  • Counting sort is a non-comparison sorting algorithm, which works on the basis of counting occurrences of each element and placing the count in a structure (call it C).
  • Once the count of the occurrences has been determined, we aim to calculate the cumulative sum within that same structure.
  • With this now we can place each value of A (call an individual value As) iterating from the end , in a new array at the index C[As] -1. (occurrence count is updated respectively, so we -1 to C[As] as one occurance has been covered).
  • This is repeated until all elements from the original array are accounted for (C is full of 0s and end of original array has been reached).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In practice when is counting sort used?

A

When k = O(n)

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

What is the requirement for radix sort?

A

That all numbers to be sorted have the same number of digits

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

Is radix sort counting sort based?

A

Yes

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

How does radix sort work?

A
  • Radix sort is another non-comparison sorting algorithm, which sorts individual digits of the number taking into account only smaller digits (e.g. for sorting tens we take into account the previously sorted units), so that any collisions can be solved by looking at the lower digits sorted beforehand. The sorting happens via counting sort.
  • This is repeated until all digits are accounted for, resulting in a final sorted sequence.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the Big-Oh complexity of radix sort?

A

O(n), as the amount of digits is linear.

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

Can counting sort be replaced with another sort within radix ?

A

Yes, any stable sort algorithm.

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

What do we exploit with non-comparison algorithms?

A

The input properties.

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