String Sorts Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How does key index counting work?

A
  1. Compute frequency counts using a count array that is of size R + 1, using the key itself as an index. Therefore count[a[i] + 1]++
  2. Create indices for distribution by cumulating, for r = 0 -> R, count[r+1] = count[r]. This tells us how many keys appear before r, and thus gives the index of r at a[]
  3. Go through whole given aray. Access the count array using the char at the given array, add it to the index = count in the aux array and increment the count of the character
  4. Copy aux over to original array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does LSD String sort work?

A

Consider characters from right to left
Perform key-indexed counting on each char of the strings
Each string needs to be the same length

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

How does MSD work?

A

Create count array of size R + 2 and set values to 0
1. Count frequencies of first character
2. Transform the counts into indices
3. Distribute back
2. Sort subarrays corresponding to each character excluding first. Therefore sort(array, distributed index for character, lo + count[r+1] - 1, d + 1)

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

What is the running time for LSD and MSD?

A

LSD: NW
MSD: N and Nw

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

Where is the sweet spot for LSD and MSD?

A

LSD: short fixed-length strings
MSD: Random strings

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