Home > Java > javaTutorial > body text

How to use Fibonacci search method in java

WBOY
Release: 2023-05-13 20:37:04
forward
1637 people have browsed it

1. Concept

is an improved algorithm for binary search. By using the concept of golden ratio to select search points in the sequence to search, the search is improved. efficiency. Likewise, Fibonacci search is also an ordered search algorithm.

2. Principle analysis

The Fibonacci search algorithm is basically similar to the binary search. The difference is that the binary search is a binary search, while the Fibonacci search algorithm uses the golden section characteristics of the Fibonacci sequence and uses the golden section point to search. That is, mid = left f(k-1) - 1 (f represents the Fibonacci sequence).

How to use Fibonacci search method in java

3. Example

package com.cn.dataStruct;
 
/**
 * 用Java实现斐波那契数列
 */
public class Febonacci {
    /**
     * 用递归实现斐波那契数列
     * @param i 需要得到的第i项
     * @return 第i项内容
     */
    public static int febonaccis(int i){
        if(i == 1 || i == 2){
            return 1;
        }else{
            return febonaccis(i-1) + febonaccis(i - 2);
        }
    }
 
    public static void main(String[] args) {
       System.out.println( febonaccis(6) );
    }
 
}
Copy after login

The above is the detailed content of How to use Fibonacci search method in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!