How to use Fibonacci search method in java
May 13, 2023 pm 08:37 PM1. 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Break or return from Java 8 stream forEach?
