answersLogoWhite

0


Best Answer

The binary search algorithm works by successively halving the array and determining which half the result lies in, or if the half-way point is the result. In order for that to work, the array must be in order, otherwise choosing the half-way point would be meaningless because it would not tell you which half of the array the result is located in.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why binary search algorithm did not work on an unsorted array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What search algorithm locates an item in an array by repeatedly dividing the array in half?

half means 1/2 from the whole (previous), which means 2 of 1/2, and 2 derived into binary. Ha, Binary Search is the term.


Can you use a sequential search on an unsorted array?

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.


What is the time complexity for searching an element in an array?

If the array is unsorted, the complexity is O(n) for the worst case. Otherwise O(log n) using binary search.


Which are the searching algorithm always compare the middle element with the searching elements in the given array?

binary search system


In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


Complexity of an algorithm in data structure?

* search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1) * search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1)


When is it not recommended to perform the operation of binary search?

In computer science, a binary search or half-interval search algorithm finds the position of a specified value (the input "key") in an array sorted[1][2] into order on the values of the key. At each stage, the algorithm compares the sought key value with the key value of the middle element of the array. If the keys match, then a matching element has been found so its index is returned. Otherwise, if the sought key is less than the middle element's key, then the algorithm repeats its action on the subarray to the left of the middle element or, if the input key is greater, on the subarray to the right. If the array span to be searched is reduced to zero, then the key cannot be found in the array and a special "Not found" indication is returned.A binary search halves the number of items to check with each iteration, so locating the an item (or determining its absence) takes logarithmic time. A binary search is a dichotomic divide and conquer search algorithm.Next AnswerA binary search method requires that the list of items being search should be sorted in ascending (or descending) order. If the search list is not sorted, the binary search method will not work and other search methods will be needed.


A binary search of an orderd set of elements in an array or a sequential search of the elements.Which one is faster?

A binary search is much faster.


What is best algorithm for searching?

It depends on how the data is arranged. In case it is an array, use linear search or binary search or interpolation search according as the array is sorted or not and based on the distribution of data. If some other data structures are used (like heap) for making data retrieval efficient, other algorithms exist.


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 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.


Can you modify the bubble sort algorithm to search to sort an array of characters instead of array of integers?

The bubble sort algorithm can be applied to an array of characters. Every character can be translated to an integer equivalent via the ascii table