课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Binary search arrays in Java

Binary search arrays in Java - Java教程

课程: Java Algorithms

Binary search arrays in Java

- [Instructor] Searching data is a common task in software development. In order to optimize a search algorithm, you'll need to make assumptions about your data. For example, if you know your data is sorted, you can start at the middle and then work your way towards the beginning or end of the array, depending on where the items should be located. If the array's data is sorted, one algorithm we can use is binary search. Binary search is a divide-and-conquer algorithm wherein each step, it halves the number of elements it has to search through. For example, if we had an array of sorted numbers, the algorithm would start at the middle. Depending on whether the item we're searching for is greater than or less than the item we're looking at, it would continue its search in that portion of the array. Let's say the number we're looking for is 50. The algorithm would start at search index three, or item 20. That's the middle of the array. Since 20 is less than 50, it would continue its…

内容