Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Find second smallest element of unsorted array

Help of this post we are learning about how find second smallest element in given array.

Given array Given array to find second smallest element. Stack Areamainarray [0] 53 [1] 63 [2] 23 [3] 166 [4] 23 [5] 78 [6] 45 [7] 329 [8] 42 [9] 53 [10] 55 [11] 66 [12] 34 [13] 22 [14] 32 [15] 53 [16] 66size (int) =17

Algorithm:

Execution process:

Find second smallest element Process to find second smallest element Stack Areamainarray [0] 53 [1] 63 [2] 23 [3] 166 [4] 23 [5] 78 [6] 45 [7] 329 [8] 42 [9] 53 [10] 55 [11] 66 [12] 34 [13] 22 [14] 32 [15] 53 [16] 66size (int) =17second_smallestdata(pointer)i (int) =17result (int) =23size (int) =17temp (int) =22

Time complexity of this program O(n)

Accepted Output

Array data is: 34, 21, 5, 52, 23, 12, 42, 12, 323, 33, 5, 12, 344, 23

Second smallest elements is :[12]

Another Array

Array data is: 53, 63, 24, 66, 29, 78, 45, 32, 42, 53, 55, 66, 34, 25, 32, 53, 66

Second smallest elements is :[25]

Another Array

Array data is: 53, 63, 23, 166, 23, 78, 45, 329, 42, 53, 55, 66, 34, 22, 32, 53, 66

Second smallest elements is :[23]

Given C program to finding second smallest number in array. Iterative approach.

Output
  Array data is:  53 63 23 166 23 78 45 329 42 53 55 66 34 22 32 53 66
 Second smallest elements is :[23] 

Spread the post

Recommended Posts: