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

14y 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 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).


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.

Trending Questions
Ripple factor of half wave rectifier of L-section with derivation? 3 phase panel double pole single throw breaker 2 wires from breaker going to lighted sign 120 volts each is this a 240 volt system or a 120 feeding 2 diff ballast in the sign? What are plumbing drain vents? Explain the meaning of the term encoding failure? What are the properties of an op-amp? What causes high head pressure and normal suction pressure in a air conditioner? Can you do PhD in particle physics after aerospace engineering? Write a c plus plus programs for stack using arrays? What does train steam engine use fuel for? A 24-foot ladder is placed against a vertical wall of a building with the bottom of the ladder standing on level ground 22 feet from the basse of the building? What does leed ap stand for? What is the information and or documentation required to confirm that the activity has been completed? What work does a DT engineer do? Why does your distribeter rod not line up with pis num one it is TDC? IN a real pulley system the work supplied must be? Write a c program to find Armstrong number using ifstatement? There is only a trickle of cold water coming out of the cold tap in the kitchen the pipe is blocked took the stopcock off and it has disintegrated and think the fiber washer fell into pipe? Describe the effects that may occur to the work if glue comes in contact with steel cramps? What is the physical significance of enthalpy? Where can you find a very tough C plus plus tests?