retagged by
1,172 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

6.1k
views
3 answers
2 votes
Jyoti Kumari97 asked May 25, 2019
6,110 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?
332
views
1 answers
0 votes
Manoj Kumar Pandey asked Jun 20, 2018
332 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?
648
views
1 answers
0 votes
Shankar Jha asked Jun 15, 2018
648 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 problem that can be solved in 6 minutes
634
views
1 answers
0 votes
Ray Tomlinson asked Aug 9, 2023
634 views
Suppose we have a directed graph G = (V,E) with V= {1, 2, ..., n} and Eis presented as an adjacency list. For each vertex u in V, out(u) is a list such that (u, v) in {1, 2, ... k) ... (u), u in V?T(n) =O(n+m) B. T(n)= O(n(m+n))