[22636 views]
An array is a data structure containing elements of the same data type. These elements are stored in contiguous locations in the memory.
Hence, we can easily find out the position of each element of the array by adding the base address with an offset value. Offset is the difference between two indexes of the array and the base address is the memory location of the first element of the array.
The elements of an array can be accessed through the it’s index. For example if we want to access the second element of an array, we can write: a[1]. Here the index the required variable in the array ‘a’ is 1.
Note: The index of an array always starts with 0.
Arrays are very important data structures since arrays are used to implement other data structures like stack, queue, linked-list, heaps, etc. Arrays have a very wide range of implementation. In this article, we will see the simplest approach to find out the smallest or minimum element in a given array.
In this algorithm, we will first take the size of the array as input from the user. Then we will declare an array of the size given by the user. Now, to take the elements as input, we will start a loop. The loop variable is initialized as 0. Then the elements are taken as input one by one. Once this is done, we initialize the smallest element, min, as the first element of the array, that is, a[0]. Then another loop is started with initial value 0. In this loop, we will compare each element of the array with the variable min. If the element a[i] is less than min, then value of min is replaced with the value of a[i]. When all the iterations of the loop are over, we get the minimum element in the array, stored in the variable min.
Can I get a pseudocode for this