We are given an array of size $n$ (it is not specified if we have an integer array, a specific range or any other assumptions), which might be unsorted, and a real number as a constant $k<1$. We need to prove or disprove that it is possible to output the $\lfloor n^k \rfloor$ smallest elements of a sorted order, in $O(n)$ worst case time complexity.
example: let $A$ be an array of size 4, and let $k=0.6$. The algorithm should output the smallest $\lfloor 4^{0.6}\rfloor \approx \lfloor2.29\rfloor = 2$ items in A in a sorted order.
I have two ideas here, one to prove the statement and one to disprove it, but not sure how can both be possible:
Disprove: Given that we are able to choose a $k<1$ as we wish, choose a $k=0.9999...$ so $\lfloor n^k \rfloor = n-1$. Assuming by contradiction that this algorithm is possible, we can sort the $n-1$ smallest elements of $A$, and then append the largest element in $O(n)$. This leads to a contradiction resulting from the lower bound for comparison based sorting in $\Omega(n\log n)$.
Prove: use the following algorithm:
- Find $\lfloor n^k \rfloor$'s rank in the array using median of medians and partition the array using it as a pivot.
- Preform a Heapsort on a min heap created (in $O(n)$) from the elements smaller than $\lfloor n^k \rfloor$ following the partition.
for the sorting part, calculating the time complexity might generally look like this: As $\lfloor n^k \rfloor \le n^k$ , $\lfloor n^k \rfloor * \log(\lfloor n^k \rfloor) \le k*n^k*\log(n)$. As $k<1$ $\lim_{n\to \infty} \frac{k*n^k*\log(n)}{n} = \dots =0 $, so the sorting is in $o(n)$, and the entire algorithm is in $O(n).$
I think my main issue in both is understanding the asymptotic calculation vs the practical matter of sorting an array (or that my math is entirely wrong, which is an option).
What should be the correct idea/solution?