# Algorithm and Flowchart to find the smallest element in an array

[43911 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.

### Algorithm to find out the Smallest Element in an array:

Step 1: Start Step 2: Read the size of the array from the user, say ‘n’ Step 3: Declare an array of size n, say a[n] Step 4: Initialize loop variable, i = 0 Step 5: Repeat while i < n: 5.1: Read the array element at position ‘i’ 5.2: Increment i by 1 Step 6: Initialize smallest element, min = a[0] Step 7: Initialize loop variable, i = 0 Step 8: Repeat while i < n: 8.1: If a[i] < min, then: 8.1.a: min = a[i] 8.2: Increment i by 1 Step 9: Print the smallest element, min Step 10: Stop

#### Explanation:

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.

## Flowchart to find out the Smallest Element in an array:

### Want to Learn How to write own Algorithm and Flowcharts

#### Want to test your logical skills in Algorithms?

1 comment
• Nirala Rajshekar

Can I get a pseudocode for this