Type of paper:Â | Essay |
Categories:Â | Computer science |
Pages: | 4 |
Wordcount: | 953 words |
This is one of the most popular search algorithms among the different existing algorithm. It is the most commonly used algorithm to solve various problems due to its ease of implementation as well as its runtime complexity of 0(log n). The best example of the effectiveness is the search for a particular name when given the names of the entire world as long as they are arranged alphabetically (McMillan 66). The search algorithm would accomplish the task in a maximum of 35 iterations. This leads us to the most important key feature of the algorithm. For the binary algorithm to work, the provided data must be sorted. With the data being in a sorted format, the number of iterations involved can always be reduced on the basis of the value that is being searched.
As compared to other forms of search algorithms, the binary search algorithm is closely comparable to the interpolation search algorithm although they share a few differences. The interpolation search algorithm being more advanced in relation to its search mechanism. Both utilize the divide and concur strategy where binary search algorithm involves the calculation of the middle element in an array then comparing it to the key element being searched (Neapolitan and Kumarss 352 ). On the other hand, interpolation search algorithm involves the use of a different formula to find the probe position which is usually closer to the key value being searched in the array then comparing the two. This is repeated severally. The similarity between the two is the nature of data that needs to be searched requires to be sorted first for the comparison of the elements to be accurate. Both algorithms solve the same nature of problems with a slight difference in their method of operation as explained.
Binary search algorithm works with the divide and concur rule. Binary search algorithm looks for a particular item by comparing the middle most item of the collection. If the much occurs then it returns the index of the number. If the middle number is greater than the item, then the item is searched in the sub-array which is on the left side of the middle item while in case the item is greater than the middle index then the search is done on the right side of the subarray (Neapolitan et al., 48). The process continues until the size of the subarray reduces to zero, and by this point, the item is identified. Below is an example to help explain the binary search algorithm by considering the following array; search for 49
Arr [ 10, 22, 27, 33, 38, 47, 49, 50, 55, 61]
= Arr [0 1 2 3 4 5 6 7 8 9]
The application of the linear search, the position of the 8th element will be determined by the 9th iteration in the array.
The first step before starting the search it is essential to identify the start and the ending of the range within the array which for easier understanding we could refer to them as low and high respectively.
Mid = low + (high - low) / 2
In our case the mid = 0+ ( 9 - 0 ) / 2
4.5 hence the mid value is 4
From the provided array the 4th element is
Arr [ 10, 22, 27, 33, 38, 47, 49, 50, 55, 61]
Middle value is = 38
This leads to the next step where one compares the middle element with the search element in our case 50;
50 > 38 hence the search is reduced
Arr [47, 49, 50, 55, 61]
The middle element is 50
50 = 50
Hence the result for the calculation of the next middle number is the actual such key hence the algorithm returns the value as the needed value and the steps end at this point.
Binary search algorithm has multiple advantages which make it the preferred search algorithm by many, the first being its easy nature. The implementation of the algorithm is simple and implemented by many as compared to the interpolation search algorithm. It is also faster when compared to other search algorithms such as the linear search algorithm. Linear search algorithm takes on average N/2 comparison where N is the number of elements in the provided array, and worst-case N comparisons where on the other hand binary search algorithm takes an average and worse - case log2(N). The search algorithm also has a number of disadvantages such which the fact that it can only work on data that is kept sorted (Puntambekar). With this in mind, it is impossible to implement the search algorithm to an array containing random data. This is similar with the interpolation search algorithm; both search algorithms cannot be implemented on any data that is not sorted since for the middle point calculation to be accurate the data in the array needs to be sorted. Another disadvantage is that the search algorithm cannot be applicable to any data which does not possess a less than or a greater than the relationship (Wang, Ling, et al.). This problem is also encountered with other search algorithms such as the interpolation search algorithm.
Below is an example application of the search algorithm by the Tycho - 2 catalog which contains the information about the brightest stars in the galaxy, a total of 2,539,913. In the case where one wants to search for a specific star based on the star's allocated name. And the data is well sorted then the search algorithm is applied to the task. The examining of the data can hardly go more than 22 times even in the worst-case scenario hence making the algorithm fast and effective.
Work Cited
McMillan, Michael. Data Structures and Algorithms with JavaScript: Bringing classic computing approaches to the Web. " O'Reilly Media, Inc.", 2014.
Neapolitan, Richard E., and Kumarss Naimipour. Foundations of algorithms. Jones & Bartlett Learning, 2010.
Neapolitan, Richard E., and Kumarss Naimipour. Foundations of algorithms using Java pseudocode. Jones & Bartlett Learning, 2004.
Puntambekar, Anuradha A. Analysis and design of algorithms. Technical Publications, 2008.
Wang, Ling, et al. "An improved adaptive binary search algorithm." Information Sciences 232 (2013): 58-87.
Cite this page
Free Essay about Binary Search Algorithm. (2022, May 20). Retrieved from https://speedypaper.net/essays/binary-search-algorithm
Request Removal
If you are the original author of this essay and no longer wish to have it published on the SpeedyPaper website, please click below to request its removal:
- Free Essay Answering the Question of Why People Commit Crimes
- Research Methods
- Free Essay with Lake Ellie Chemistry Analysis
- Free Essay on A Haunted House by Virginia Woolf
- Free Essay Discussing Causes and Effects of Internet Addiction
- Free Essay Offering Solutions to Organ Trafficking
- Free Essay Sample on Causes of Modern Slavery
Popular categories