answersLogoWhite

0


Best Answer

Sequential search is the only way to search an unsorted array unless you resort to a multi-threaded parallel search where all threads concurrently search a portion of the array sequentially.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you use a sequential search on an unsorted array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you search for an element in unsorted array?

Let's use integers as an example. int elementToFind; // the element we want to search for int[] elementArray; // the array we want to search through boolean found = false; //boolean flag to indicate if we found the element or not for(int i = 0; i < elementArray.length; ++i) { if(elementArray[i] == elementToFind) { // we found the element at index i // do whatever you want to do with this information found = true; } //if found is still false so it means this element is not found if(!found) { //the element is not found in the array } }


Which algorithm is preferable to find a specific number from unsorted array?

If the array is unsorted then there is no algorithm that can be applied other than a sequential traversal from one end of the array to the other until the number is found or the end of the array is reached. This is an extremely poor algorithm as the worst case would be O(n) for n elements. While this may be fine for small arrays, it is highly inefficient for larger arrays. To apply a more efficient algorithm with a worst case of O(log n), you must sort the array. You can then use a binary search algorithm by starting at the middle element. If that's your value, you're done. If not and the value you seek is less than this value, then you can eliminate all the elements in the upper half of the array, otherwise you can eliminate all the elements in the lower half of the array. Repeat the process with the remaining subarray, reducing the number of remaining elements by half each time. If you end up with a subarray with no elements then the value does not exist. Sorted arrays that are perfectly balanced offer the best performance. For instance, an array with 63 elements is perfectly balanced because after the first iteration you are left with another perfectly balanced array of 31 elements (because you eliminated 31 elements plus the middle element). After the next iteration you will be left with 15 elements, then 7, 3, 1 and finally 0. Thus a 63-element array takes no more than 6 iterations to determine that a value does not exist, compared to 63 iterations with a sequential traversal search upon an unsorted array. 6 iterations is also the average because the 6th iteration can locate any one of 32 values, which is more than half the values.


What is the simplest search technique to use to find an item in an array?

Linear search


What condition linear search is better than binary search?

In linear search, the searched key will be compared with each element of the array from the beginning and terminate comparing when the searched key is found or the array is reached. Here time complexity in worst case and average case is O (n). To find an element quickly we use divide and conquer method by using binary search algorithm. Here probed region is reduced from n to n/2. Time complexity is O (log2 n), but here the array should be sorted. But in interpolation search the probed region is reduced from n to n1/2. If the array elements are uniformly distributed the average case complexity is O (log2 (log2n)). Am also searching for hashing to compare & contrast with above.


Why do you use hashing and not array?

Hashing provides a method to search for data.Hashing provides a method to search for data.Hashing provides a method to search for data.Hashing provides a method to search for data.

Related questions

How do you search for an element in unsorted array?

Let's use integers as an example. int elementToFind; // the element we want to search for int[] elementArray; // the array we want to search through boolean found = false; //boolean flag to indicate if we found the element or not for(int i = 0; i < elementArray.length; ++i) { if(elementArray[i] == elementToFind) { // we found the element at index i // do whatever you want to do with this information found = true; } //if found is still false so it means this element is not found if(!found) { //the element is not found in the array } }


Which algorithm is preferable to find a specific number from unsorted array?

If the array is unsorted then there is no algorithm that can be applied other than a sequential traversal from one end of the array to the other until the number is found or the end of the array is reached. This is an extremely poor algorithm as the worst case would be O(n) for n elements. While this may be fine for small arrays, it is highly inefficient for larger arrays. To apply a more efficient algorithm with a worst case of O(log n), you must sort the array. You can then use a binary search algorithm by starting at the middle element. If that's your value, you're done. If not and the value you seek is less than this value, then you can eliminate all the elements in the upper half of the array, otherwise you can eliminate all the elements in the lower half of the array. Repeat the process with the remaining subarray, reducing the number of remaining elements by half each time. If you end up with a subarray with no elements then the value does not exist. Sorted arrays that are perfectly balanced offer the best performance. For instance, an array with 63 elements is perfectly balanced because after the first iteration you are left with another perfectly balanced array of 31 elements (because you eliminated 31 elements plus the middle element). After the next iteration you will be left with 15 elements, then 7, 3, 1 and finally 0. Thus a 63-element array takes no more than 6 iterations to determine that a value does not exist, compared to 63 iterations with a sequential traversal search upon an unsorted array. 6 iterations is also the average because the 6th iteration can locate any one of 32 values, which is more than half the values.


What is the simplest search technique to use to find an item in an array?

Linear search


What condition linear search is better than binary search?

In linear search, the searched key will be compared with each element of the array from the beginning and terminate comparing when the searched key is found or the array is reached. Here time complexity in worst case and average case is O (n). To find an element quickly we use divide and conquer method by using binary search algorithm. Here probed region is reduced from n to n/2. Time complexity is O (log2 n), but here the array should be sorted. But in interpolation search the probed region is reduced from n to n1/2. If the array elements are uniformly distributed the average case complexity is O (log2 (log2n)). Am also searching for hashing to compare & contrast with above.


How delete an array of object within the object in C?

First locate the position of an array by search after than use a delete function to delete an array


How do you represent binary search and linear search in graphics using c plus plus?

Linear search usually implies the data sequence is in an unsorted order or does not provide random access iterators (such as a list). Essentially you start from the beginning and traverse through each element until you find the element you are looking for, or reach the "one-past-the-end" iterator (which means the value does not exist). With binary search you use a sorted sequence, such as a sorted array. You start in the middle of the sequence. If the value is not there, you know which half of the array the value must be in, so you start in the middle of that half. By eliminating half the array (or sub-array) each time you will either find the value or you end up with an empty sub-array (which means the value does not exist). You can also use binary search on a binary tree which achieves the same thing, but the tree must be perfectly balanced (such as a red/black tree) to be of benefit.


How can you use the word thither in a sentence?

The traveler journeyed from here to thither in search of new adventures.


Is there any precondition to apply binary search procedure?

Sure. You have to have direct access to the sorted elements. You cannot use it if the elements are unsorted, or you cannot access them directly (magnetic tape for example).


What is sequential connectives?

sequential connectives are connectives you use in explanation text.


Why do you use hashing and not array?

Hashing provides a method to search for data.Hashing provides a method to search for data.Hashing provides a method to search for data.Hashing provides a method to search for data.


What is the definition of hlookup?

It is a function that means horizantal lookup. you use it to search for a value in the first row of a table array and a return a value in the same column from another rowin the table array


What is the definition of vlookup?

It is a function that means vertical lookup. You use it to search for a value in the first column of a table array and returns a value in the same row from another column in the table array.