01 Fun heap data structure and the priority queue _08_

stack:

This tree structure itself in the field of computer science occupies a very important position, the reason why this data structure plays an important role, not only because such a structured binary search tree, the tree itself is such a shape can produce a lot of development, for different problem, we can slightly change or limit the nature of such a tree data structure, resulting in different data structures, different problems efficient solution,

From the beginning of the section, there will be four different examples of introduction four chapters, which are heap, tree line, the dictionary tree and disjoint-set by these different structures of the tree, we can understand the flexibility to place data structure ,  

What is the priority queue:

Priority Queuing (relatively high-level data structures) are a team, irrespective of the team and order, and   priority   related, in fact, with most of the team who is a priority,

 

Interface and normal queue priority queue is the same, just on a team and the team's first operating elements are different,

 

 

Priority queue substructure implementations are also may be composed of different data structures, provided herein are three types of data structure (general linear structure linear sequence structure, stack )

 

It is assumed that the priority of who is the greatest,

Here is a stack data structure as the underlying implementation of a priority queue, it may also be used if there is time general linear structure or a linear structure sequentially implemented priority queue priority queue and then with stack implemented here to compare the performance, which helps the results of the study of data!

 

The basic structure of the heap:

In the world of the computer, all the time complexity is logn, then almost certain and tree this structural relationship, merge sort and quick sort they are logn level, (although not directly use the tree, but it's a recursive process is actually a invisible tree)

A heap itself, it is actually a tree ,  

 

Binary heap:

Binary heap is a special tree, binary heap is a lesson complete binary tree ,   

Full Binary: except the last one without any child node , all the nodes on each layer has two child nodes of the binary tree. 

Complete binary tree: a complete binary tree is a full binary tree and lead out. The depth is K, there is a binary tree of n nodes, if and only if called binary tree nodes each of which are the full depth of K binary tree node numbers following from 1 to n.

Full binary tree: 

 

Complete binary tree: (in fact, layers of release, until fit inside)

First of all binary heap is a complete binary tree, in addition,

It also has a special property: heap value of each node is always greater than the value of its parent node ( all nodes values are greater than the value of its children ) . This time the heap, we call the maximum heap (each node values are greater than the value of its child nodes), you can also define appropriate minimum heap! 

 

Summary : the greatest heap: the first is a complete binary tree, then, the value of each node is greater than the value of its child nodes! 

 

 

 

 

 

 

 

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/zach0812/p/11831890.html