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).
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) ); } }
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!