wiz-icon
MyQuestionIcon
MyQuestionIcon
3
You visited us 3 times! Enjoying our articles? Unlock Full Access!
Question

An array 'S' contain n distinct elements. Consider a functionfi which is defined as:

fi={max(a,b,c)|a,b,cSandabc}

What is the worst case time complexity to find set of all possible elements which are returned by function fi
when array 'S' is passed as an argument?

A

O(n2)

No worries! We‘ve got your back. Try BYJU‘S free classes today!
B

O(n3)

No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
O(n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
O(n logn)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C O(n)
(a)
If we observe their are nC3 sets of 3-element possible. Out of n-elements only 2-samellest element cannot be present in " max-element set ". So we can use 2-pass of selection sort to find 2-smallest elements, other than these two elements all will be present in "max-element set". So it will take
O(n) time.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Covalent Bonds
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon