Spread the post

Find second largest element of unsorted array

Write an efficient algorithm to find second largest of given unsorted array.

Example

Given Unsorted array Given unsorted array Goal Find Second Big [1st] Big 11 [1nd] Big 9 Stack Areamainarray [0] 1 [1] 2 [2] 9 [3] 5 [4] 2 [5] 4 [6] 8 [7] 7 [8] 11size (int) =9

Suppose given an array.

Algorithm:

Execution Process:

Time complexity of this program O(n).

Stack Areamainarray [0] 1 [1] 2 [2] 9 [3] 5 [4] 2 [5] 4 [6] 8 [7] 7 [8] 11size (int) =9second_largestdata(pointer)first (int) =11i (int) =9result (int) =9size (int) =9

C Program to find second largest element in unsorted array.

Output

Thanks for Rakesh kumar to correct this post

Spread the post

Recommended Posts: