answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which algorithm is preferable to find a specific number from unsorted array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are steps of algorithm?

the number of steps of an algorithm will be countable and finite.


Algorithm to convert a number representing radix r1 to r2?

algorithm to convert a number representing radix r1 to radix r2


Design an algorithm to find a reverse of number?

An example of an algorithm that will reverse a number is written as such, digit reverse(num), while (num>0) then, digit =num%10. This particular algorithm divides a number by 10 until the original number from the LSD is found.


Where do you run an algorithm?

By preparing test cases we can test an algorithm. The algorithm is tested with each test case.


What is an algorithm to calculate the sum of the digits of a three digit number?

algorithm is a way to solve your problem


Write an algorithm to check whether a number is a prime number or not?

You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.


What is algorithm in basic computer science?

An algorithm is a set of instructions that a computer follows, generally to accomplish one specific task. These tasks can range from sorting a set of numbers to finding the greatest common denominator of two numbers.


What is booth's algorithm?

It is a powerful algorithm for signing up a number of multiplication. It generates a 2n bit product and it treats both +ve & -ve number uniformly.


Algorithm A completes 3 cycles in one minute. Each of Algorithm B and Algorithm C respectively completes 4 and 5?

The full Question...Suppose 3 algorithms are used to perform the same task for a certain number of cycles. Algorithm A completes 3 cycles in one minute. Each of Algorithm B and Algorithm C respectively completes 4 and 5 cycles per minute. What is the shortest time required for each Algorithm to complete the same number of cycles?


How to write an algorithm that accepts five numbers and displays the sum and average of the numbers?

1.Start Algorithm 2.Enter first number 3.Enter second number 4.Enter third number 5.Enter fourth number 6.Enter fifth number 7.Add five number 8.display five number / 2 9.Display result 10.End Algorithm


What is the algorithm for adding negative numbers?

subtract the positive number


How can i find an algorithm to determine the largest number?

1,000000000000,00000000000000,00000000,000000000000,00000000000,00000000000,00000,0000000000,000000,actually, there is no such thing as 'the largest number'.