Sequential search is an algorithm in which a data structure, such as an array or a list, not known to be sorted is searched element by element from beginning to end for a specific value.
On the AP Computer Science Exam, you must recognize the algorithm when it is presented in code. You should also be able to recognize a variation of the algorithm, such as a search from the end to the beginning. You may be expected to compare the efficiency of sequential search to (the much more efficient) binary search.
Method sequentialSearch is to returns the index of key in x or -1 if key is not in x.
Complete method sequentialSearch below.
public static int sequentialSearch(int x, int key)