Sequential search The sequential search(also called the linear search) on array
ID: 3653870 • Letter: S
Question
Sequential search The sequential search(also called the linear search) on array based list is described in chapter 3 and the sequential search on linked lists is covered in chapter4. The sequential search works the same for both array-based and linked lists. The search always starts at the first element in the list and continues until either the item is found in the list is searched. Because we are interested in the performance of the sequential search ( that is the analysis of this type of search), for easy reference , next we give the sequential search algorithm for array based list. If the search item is found, its index(that is its location in the array) is returned. If the search item is found, its index( that is its location in the array) is returned. It the search is unsuccessful, -1 is returned.(note that the following sequential search does not require the list element to be in any particular order) public int seqSearch(DataElement searchItem) { int loc; boolean found = false; for(loc = 0; loc < length; loc++) if(list[loc].equals(searchItem)) { found = true break; } if(found) return loc; else return -1 }//end seqSearchExplanation / Answer
#include #include void main() { clrscr(); int a[20],n,x,i,flag=0; coutn; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.