Question: Write an efficient C program to find smallest and second smallest element in an array.
Solution
Method 1 - Compare each element with current max and second max
Algorithm
1) Initialize both first and second smallest as a
0 first = second = a
0 2) Loop through all the elements. a) If the current element is greater than firstMax, then update firstMax and secondMax. b) Else if the current element is greater than second then update secondMax pseudocode
[Read More]