Examples of two common simple search algorithms implemented in Java [fast search and binary search]

This paper describes two common simple search algorithms implemented in Java. Share with you for your reference, as follows:

preface:

Search refers to the process of finding a record that meets the specified conditions from a batch of records.

It is often used in the preparation of ordinary programs. Here are two search algorithms

1. Quick search:

This is quite simple. Take the array as an example, use a for loop to find the data to be found in the array

example:

2. Binary search:

Dichotomy search requires that the data sequence must have a linear structure, that is, the data sequence must be arranged in order to use dichotomy.

Direct example (recursion can be used when dichotomy is used):

For more information about Java algorithms, readers who are interested can see the topics on this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>