Java Fundamentals--two-point method

Source: Internet
Author: User
BinarySearch

Binary search, as the name implies is to be divided into two pieces of data each time and then to find the data you want, we can think of, the dichotomy to find very similar to our usual guessing price game, when you quote a price, the referee will tell you the price relative to the true value of the high and low, If it is low, then we will certainly say a slightly higher price, and vice versa. The binary lookup requires that the incoming data must be ordered, assuming that it is now ascending, and then each time the value being looked for is compared to the median (the left edge of the array + (right boundary-left boundary)/2), the larger one looks for the median left-hand data, and the lower-right data for the median value.

Algorithm: It is suitable to use this method when the amount of data is large. When searching by binary method, the data need to be ordered and not duplicated.

Given an array of {12, 23, 34, 45, 56, 67, 77, 89, 90}, it is now required to use a dichotomy to find the specified value and return it at the index of the array, or 1 if not found.

Java Fundamentals--two-point method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.