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

Spread the post

Find the largest element of unsorted array in c?

Example:

Suppose assume that following element are exist in unsorted array.

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 :

Use one integer variable result and assign a first element of array. if result variable value are less than array element then assign new value to result variable. continue this process untill last element of array. And result are largest element of array.

Accepted Output

Other example

Array data is : 23, 5, 21, 51, 111, 34, 12, 121, 44, 22, 113, 112

Result is : [121]

Array data is : 322, 444, 12, 66, 233, 466, 233, 11, 3, 4, 112, 443, 221

Result is : [466]

Time complexity of this program O(n)

Below in C implementation of this problem. Iterative approach.



Code execution:

Find higher element of given array here includes execution process.

Try it yourself.

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) =17find_largestdata(pointer)i (int) =8result (int) =329size (int) =17

Spread the post

Recommended Posts: