In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to understand Java data structures and algorithms". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Basic introduction
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Fibonacci refers to the division of a line into two parts so that the ratio of one part to the total length is equal to the ratio of the other to this part. The approximate value of the first three digits is 0.618. Because the shape designed according to this proportion is very beautiful, it is also known as golden section, also known as Sino-foreign ratio.
The Fibonacci sequence {1 magistrate, 2 magistrate, 3 magistrate, 5 magistrate, 13 magistrate, 21 magistrate, 34 Magi 55} found that the proportion of two adjacent numbers of the Fibonacci sequence is infinitely close to the golden section value of 0.618.
Fibonacci search principle
The principle of Fibonacci search is similar to that of binary search and interpolation search, only changing the position of the intermediate point (mid). Mid is no longer intermediate or interpolated, but is located near the golden section point, that is, mid = low+F (k Mel 1)-1 F represents the Fibonacci sequence, as shown in the following figure
The understanding of F (kmur1)-1:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Because of the property of Fibonacci sequence F [k] = F [k-1] + F [k-2], we can get * * (F [k]-1) = (F [k-1]-1) + (F [k-2]-1) + 1 *. The formula states that if the length of the main sequential table is F [k]-1, the table can be divided into two segments with lengths of * * F [k-1] and F [k-2] * *, as shown in the figure above. So the middle position is: mid = low+F (KMel 1)-1.
Similarly, each field can be split in a similar way.
However, the sequence table length n is not exactly equal to F [k]-1, so it is necessary to increase the original sequence table length n to F [k]-1. As long as the k value here can make F [k]-1 exactly greater than or equal to n, it can be obtained from the following code. After the length of the sequence table increases, the new position (from n [k]-1 to F [k]-1) is assigned to the value of n position.
While (n > fib (k)-1) {kapphire;}
Code case
Package com.xie.search; public class Fibonacci {public static void main (String [] args) {int arr [] = {1,8,10,89, 1000, 1234}; int n = 6; int x = 1; / int [] arr = new int [1234]; / / for (int I = 0; I)
< 100; i++) { // arr[i] = i; // } // int n = 100; // int x = 1; System.out.println("Found at index: " + fibMonaccianSearch(arr, x, n)); } /** * 返回x和y最小的数 * * @param x * @param y * @return */ public static int min(int x, int y) { return (x 1) { // 检查fibMm2是否为有效位置 int i = min(offset + fibMMm2, n - 1); /* 如果x大于索引fibMm2处的值,则将从offset到i切割为子数组 */ if (arr[i] < x) { fibM = fibMMm1; fibMMm1 = fibMMm2; fibMMm2 = fibM - fibMMm1; offset = i; } else if (arr[i] >X) {/ * if the value at index fibMm2 is less than the value at index arr.length-1, the array will be cut from iTun1 to arr.length-1 * / fibM = fibMMm2; fibMMm1 = fibMMm1-fibMMm2; fibMMm2 = fibM-fibMMm1;} else {/ * if found, index * / return I will be returned }} / * compare the last element to x * / if (fibMMm1 = = 1 & & arr [offset + 1] = = x) {return offset + 1;} / * No search, return-1 * / return-1 This is the end of "how to understand Java data structures and algorithms". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.