retagged by
1,068 views
0 votes
0 votes

retagged by

3 Answers

2 votes
2 votes
Here, worst case can occur if we want the $\frac{n}{2}^{th}$ smallest element and if you have a trillion of elements, you need to bother about your algorithm design.

 

So, one can think of like running $\frac{n}{2}$ passes of selection sort and giving answer as O(n), but it will be wrong because your $i$ can be anything ranging from 1 to n and if it is $\frac{n}{2}$ then, since each pass requires O(n), this will amount to total of

$\frac{n}{n}*n=O(n^2)$ considering n to be very large.

Now,I will look for the best algorithm that can sort my huge list of numbers and yes we have  O(nlogn) algorithms which can do that. So, once we have sorted our elements, we can return the $i^{th}$ smallest element in O(1) time amounting to a total runtime of O(nlogn)
edited by
0 votes
0 votes

Array can be sorted in O(nlogn) & then i-th element can be found in O(1) using just index.

So, tightest bound of worst case ==> O(nlogn)

0 votes
0 votes
option : c is correct &  if in question mention that  (i<<n ) then option b is true

Related questions

2 votes
2 votes
3 answers
1
Jyoti Kumari97 asked May 25, 2019
6,021 views
Question:$T(1)=1$$T(n) = 2 T(n - 1) + n$evaluates to?Can anyone solve it by substitution method?Given answer $T(n) = 2^{n+1} - (n+2)$How?
0 votes
0 votes
1 answer
2
Manoj Kumar Pandey asked Jun 20, 2018
316 views
We've been given an unordered list having n distinct elements,the no. Of comparison to find an element that is neither the 2nd minimum nor the 2nd maximum is?
0 votes
0 votes
1 answer
3
Shankar Jha asked Jun 15, 2018
603 views
Assume that merge sort algorithm in the worst case takes 30 seconds for an input of size 64 which of The following most closely approximates the maximum input size of a p...