The Polachi is made up of a minimum set of ordered trees, each of which follows the minimum heap nature, and each tree is rooted and unordered. The root of all trees is formed by the left and right pointers to form a circular doubly linked list, called the root table of the heap.
For a given Fibonacci Polachi H, it can be accessed by pointing to the tree root pointer h.min containing the minimum keyword. Each node in the heap also contains x.mark,x.degree two fields, X.degree represents the number of children in the children's table of x, and X.mark indicates whether or not a child has been lost since X last became a child of another node.
The structure of the Fibonacci retracement is as follows:
Potential energy functions:
The performance of the Fibonacci Polachi can be analyzed using the potential energy method. Its potential function is defined as:
where M (h) refers to the number of labeled nodes in H, and T (h) represents the number of trees in the root table of H.
Maximum number of degrees:
Suppose that in a Fibonacci heap with n nodes, the maximum number of nodes is another known upper bound D (n), there are:
Extract the Fibonacci Polachi minimum code as follows:
#include <iostream> #include <cstdlib>using namespace std;typedef struct Fibheapnode{int key;int degree; Fibheapnode *left; Fibheapnode *right; Fibheapnode *parent; Fibheapnode *child;bool Mark; Fibheapnode (int k): Key (k), degree (0), left (null), Right (NULL), parent (null), child (NULL), Mark (false) {}}fibheapnode; typedef struct FIBHEAP{INT Num; The number of node in the Heapfibheapnode *min; The minimum heap,root node//int maxdegree; Maximum degree}fibheap;void addnodetorootlist (Fibheapnode *hmin,fibheapnode *x) {x->right = Hmin->right;x- >left = hmin; if (hmin->right!=null) hmin->right->left = x; Hmin->right = x;} void Fibheap_make (Fibheap *h) {h->num=0; h->min=null;//h->maxdegree=0;} void Fibheap_insert (Fibheap *h,int k) {Fibheapnode *x=new fibheapnode (k); if (h->min==null) h->min=x;else{ Addnodetorootlist (h->min,x); if (X->key < H->min->key) h->min = x;} h->num++;} void Fibheap_create (Fibheap *h,int a[],int N) {fibheap_make (H); for (int i=0;i<n;i++) Fibheap_insert (H,a[i]);} int main () {int test_data[]={52,18,17,38,39,41,3,30,24,26,46,35,7,23};int n=sizeof (test_data)/sizeof (int); Fibheap *h=new fibheap (); Fibheap_create (h,test_data,n);cout<< "hmin=" <The results of the operation are as follows:
"Note: If there is an error, please correct it ~ ~ ~"
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Introduction to Algorithms 19th: Fibonacci Polachi