answersLogoWhite

0

int linearSearch(int a[], int first, int last, int key) { // function: // Searches a[first]..a[last] for key. // returns: index of the matching element if it finds key, // otherwise -1. // parameters: // a in array of (possibly unsorted) values. // first, last in lower and upper subscript bounds // key in value to search for. // returns: // index of key, or -1 if key is not in the array. for (int i=first; i<=last; i++) { if (key == a[i]) { return i; } } return -1; // failed to find key }

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is search algorithm?

The linear search algorithm is a special case of the brute force search.


What is linear searching?

The linear search algorithm is a special case of the brute force search.


How does the jump search algorithm improve the efficiency of searching for a specific element in a sorted array?

The jump search algorithm improves search efficiency by jumping ahead in fixed steps to quickly narrow down the search range, making it faster than linear search. It then performs a linear search within the smaller range to find the specific element in a sorted array.


How can you convert a simple algorithm to recursive algorithm?

Linear search(a,item) n=length(a) for i=1 to n do if(a[i]==item) then return i end for return -1


What is the best search algorithm to use for an unsorted array?

The best search algorithm to use for an unsorted array is linear search. It involves checking each element in the array one by one until the desired element is found. This algorithm has a time complexity of O(n), where n is the number of elements in the array.


What is the offset for a Class C IP address in Google's search algorithm?

The offset for a Class C IP address in Google's search algorithm refers to the specific location within the search results where a website appears based on its IP address.


The time complexity of the sequential search algorithm is?

O(N) where N is the number of elements in the array you are searching.So it has linear complexity.


Give you the algorithm of creating a new binary search tree using c?

i want to know how to give the algorithm password in a computer ?


How do you search a particular element from the vector?

To search a particular element from the vector, use the find() algorithm. If the vector is sorted, you can use the binary_search() algorithm to improve efficiency. Both algorithms can be found in the &lt;algorithm&gt; header in the C++ standard library.


What is the best search algorithm to use for a sorted array?

The best search algorithm to use for a sorted array is the binary search algorithm.


What algorithm uses a loop to step through each element of an array starting with the first element searching for a value?

What you're describing is called a sequential search or linear search.


Best first search program in c?

The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).