Finding the second smallest element with the minimum number of comparisons:
Let’s assume that the unordered sequence contains n elements. Then we can find the smallest element in n-1 comparisons.
We can do this by having a variable (let’s call it ‘minNum’), and storing the first value in it. Then comparing the ‘minNum’ with every value in the list and keep replacing the value in the variable with the smallest number in each comparison.

We can also find the smallest by dividing the list into multiple pairs and comparing within them, then keep repeating until it leaves us with the…

Ramanan Durairaj

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store