Sequential Searching
Sequential Searching
SEQUENTIAL SEARCHING
ALGORITHM: 1. Input A (array), size (size of the array), target (value to be searched). 2. Initialize i to 0. 3. If i is equal to size go to step 5, otherwise proceed to step 4. 4. If (A[i] == target), return i. Otherwise go to step 3. 5. STOP
INDICES 9 0 7 1 3 2 15 3 17 4 11 5 5 6 19 7 13 8 1 9
Target
= 15
Size of Array = 10
9 0
7 1
3 2
15 3
17 4
11 5
5 6
19 7
13 8
1 9
Description At the beginning, the entire array is unsorted and user-defined. Now, we try to search the value 15 from the array.
9 0
7 1
3 2
15 3
17 4
11 5
5 6
19 7
13 8
1 9
Description To perform the linear search on unsorted array, it is done by examining the elements in the array starting from the first position. Since 9 is not our search value, we continue our search.
9 0
7 1
3 2
15 3
17 4
11 5
5 6
19 7
13 8
1 9
Description Continue our checking on every element of the array until either we found our search value or all the elements in the array have been examined. Since 7 is not equal to our target, continue the searching.
9 0
7 1
3 2
15 3
17 4
11 5
5 6
19 7
13 8
1 9
Description: Since 3 is not the same with our target, continue our search.
9 0
7 1
3 2
15 3
17 4
15 5
5 6
19 7
13 8
1 9
Description: We have found our search value 15, which is at the index position [3].