27 lines
777 B
Markdown
Raw Normal View History

2019-10-15 20:59:32 +05:30
Radix Sort
2019-10-14 15:04:31 +05:30
----------
2019-10-15 20:59:32 +05:30
- sort elements from lowest significant to most significant values
- explain: basically counting sort on each bit / digit
- **Stability:** inherently stable - won't work if unstable
- **complexity:** $O(n \log\max a[i])$
2019-10-14 15:04:31 +05:30
2019-10-15 20:59:32 +05:30
Sex-Tuples
----------
> Given A[n], all distinct
> find the count of sex-tuples such that
> $$\frac{a b + c}{d} - e = f$$
> Note: numbers can repeat in the sextuple
- Naive: ${n \choose 6} = O(n^6)$
- Optimization. Rewrite the equation as $ab + c = d(e + f)$
- Now, we only need ${n \choose 3} = O(n^3)$
- Caution: $d \neq 0$
- Once you have array of RHS, sort it in $O(\log n^3)$ time.
- Then for each value of LHS, count using binary search in the sorted array in $\log n$ time.
- Total: $O(n^3 \log n)$
2019-10-14 15:04:31 +05:30