An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is
A
Θ (1)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
Θ (n log n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Θ (n log n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Θ (n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is AΘ (1) Take first 3 elements. The middle of the 3 elements will be the element that is neither minimum nor maximum in the array. Hence O(1) time to compare 3 elements. Example: Assume 4. 6, 2 are first three elements. Then 4 is the middle element of 4. 6 and 2. Which is neither minimum nor maximum.