what is a bucket sort?
What is the time complexity of a bucket sort?
What is a radix sort?
What is the time complexity of a radix sort
d is the number of columns it has to perform a bucket sort on, so the time complexity = O(d*(N+n))
How do we perform a radix sort on words of uneven length?
We make the words equal length by introducing a dummy character, that doesn’t belong to the alphabet, repeatedly for each extra character to make them equal length, then we can compare them.
- we class the dummy character as smaller than any letter in the alphabet (since it’s an empty space) so at_ _ will always be smaller than ata_
When is a sorting algorithm described as stable?
If it is order preserving
- so if there’s a tie on the ith column, then the original order of the two elements remains unchanged
-
Why does choosing to go from left to right (MSB) or right to left (LSB) make a difference in Radix sorting?
Depending on what you’re sorting, it could mean it sorts it into the wrong order
- for example since we read words from left to right, we have to compare them using the leftmost or most significant bit
- but since we ready binary numbers from the left, we need to compare them using the rightmost bit or least significant bit
- otherwise the comparison would be wrong!
If we have integers of 6 digits and 4 digits long, and we perform a radix sort, what is the value of d?
What type of algorithm is a merge sort?
A divide and conquer algorithm
What type of algorithm is a quicksort?
What is the general outline for using the divide and conquer method?
How do we analyse the running time of a divide and conquer algorithm?
we use a recurrence relation T(n) which denotes running time based on input size n
What is the recurrence relation we use to characterise running time of a merge sort?
T(n) = {c if n < 2, 2T(n/2)+cn if otherwise}
- since if the list is smaller than 2, we know if the item is found or not, else wise keep dividing the list cn and doing the comparison - n
What is a recurrence relation?
An equation that defines a sequence based on a rule that gives the next term as a function of the previous terms
What is the recurrence relation for a binary search?
What is the substitution method?
one method of solving a divide and conquer recurrence equation is to use the iterative substitution method, called plug and chug
Why can we replace the 2*T(n/2^i) in a recurrence relation?
Since we know that T(n/2^i) = 1 so we can exchange it for c since T(n) = c when n < 2
What is a general equation for a recurrence relation if we were to guess it
T(n) = {c if n <= d, a*T(n/b)+f(n) if n > d}
What conclusions about the asymptotic form of T(n) can we draw from T(n) = {c if n <= d, a*T(n/b)+f(n) if n > d}?
what is case 1 of the master method?
where e > 0, if f(n) is O(n^logn(a-e)) then T(n) = Θ(n^logb(a))
what is case 2 of the master method?
if f(n) is Θ(n^logb(a)log^k(n)) then T(n) = Θ(n^logb(a)log^k+1(n))
what is case 3 of the master method?
e > 0 and k < 1, if f(n) is Ω(n^logb(a+e)) where af(n/b) <= kf(n/b) and n >= d then T(n) = Θ(f(n))
How can we change the recurrence 2T(n^1/2) + logn into a form that allows us to use the master method?
What is it called when we have to introduce a new function S using substitution to get the recurrence relation into the correct form to use the master method?
A variable change