A priority queue is an abstract data type similar to a regular queue or stack data structure in which each element additionally has a “priority” associated with it. In a priority queue, an element with high priority is served before an element with low priority.

In daily life, we would assign different priorities to tasks, start working on the task with the highest priority and then proceed to the task with the second highest priority. This is an example of a Priority Queue.

A common misconception is that a Heap is the same as a Priority Queue, which is not true. A priority queue is an abstract data type, while a Heap is a data structure. Therefore, a Heap is a way to implement a Priority Queue.

There are multiple ways to implement a Priority Queue, such as array linked list. However, these implementations only guarantee O(1) time complexity for either insertion or deletion, while the other operation will have a time complexity of O(N). On the other hand, implementing the priority queue with Heap will allow both insertion and deletion to have a time complexity of O(logN).


A Heap is a special type of binary tree. A heap is binary tree that meets the following criteria:

  • is a complete binary tree
  • the value of each node must be no greater than (or no less than) the value of its child nodes.

A Heap has the following properties:

  • Insertion of an element into the Heap has a time complexity of O(log N)
  • Deletion of an element from the Heap has a time complexity of O(log N)
  • The maximum/minimum value in the Heap can be obtained with O(1) time complexity

There are two kinds of heaps: Max Heap and Min Heap.

  • Max Heap: Each node in the Heap has a value no less than its child nodes. Therefore, the top element (root node) has the largest value in the Heap
  • Min Heap: Each node in the Heap has a value no larger than its child nodes. Therefore, the top element (root node) has the smallest value in the Heap.

这里说明一下,什么是complete binary tree
In a complete binary tree, all the levels of a tree are filled entirely except the last level. In the last level, nodes might or might not be filled fully. Also, let’s note that all the nodes should be filled from the left.

Heap的讲解 - 介绍相关推荐

  1. 炉石传说android手机版本,炉石传说安卓版下载gpu型号选择详细讲解介绍

    炉石传说安卓版下载gpu型号选择详细讲解介绍.炉石传说手机版已经正式上线,炉石传说IOS版以及安卓版都已经正式开放下载.好多小伙伴对于怎么下载以及下载gpu型号不知道该怎么选择,兔玩网小编就为大家带来 ...

  2. 堆区(Heap)详细介绍

    1. 核心概念 1.1 堆区的特点 堆可以是物理上不连续的内存空间,但是在存储逻辑上是连续的.如果问你是否所有对象都分配到堆上,你需要回答出来一个逃逸分析和栈上分配的观点,后面有提到. 一个JVM实例 ...

  3. ae灯光插件_AE教程|Particular粒子插件全面讲解介绍官方视频教程 「中文字幕」...

    关注并私信"particular"获取教程 教程简介 Particular 粒子插件的强大和受欢迎程度,相信不用大脸多介绍,它是AE软件中最常用的一款粒子插件.这套教程是 RedG ...

  4. 堆(Heap)数据结构介绍

    堆 定义 堆是一种特别的完全二叉树,分为两种:大顶堆和小顶堆. 小顶堆(min heap):父节点的值恒小于等于子节点的值: 大顶堆(max heap):父节点的值恒大于等于子节点的值. 实现 由于堆 ...

  5. python数据库介绍_Python数据库:MYSQL讲解介绍

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 以下文章来源于我偶像龟叔,作者我偶像龟叔 MYSQL是目前应用最广泛.普及度最高的 ...

  6. 华数工业机器人教学视频_华数六轴工业机器人技术知识讲解介绍

    1.1  通用六关节-JR系列 包含JR603工业机器人适用于装配领域:JR605工业机器人,适用于手机打磨.视觉引导和装配领域:JR612工业机器人适用于上下料.弧焊.打磨.喷釉:JR620L工业机 ...

  7. 【C语言】算数操作符 移位操作符 以及 sizeof单目操作符讲解

    目录 1.算术操作符 2. 移位操作符 2.1 左移操作符 2.2 右移操作符 3.sizeof 单目操作符介绍 操作符介绍: C语言操作符分为: 算术操作符 移位操作符 位操作符 赋值操作符 单目操 ...

  8. [转]讲解安装Ubuntu nfs配置系统

    转自:http://os.51cto.com/art/201001/176511.htm 对大家推荐很好使用的nfs服务系统之前,像让大家对Ubuntu nfs服务系统有所了解,然后对Ubuntu n ...

  9. 数据结构与算法(6) -- heap

    binary heap就是一种complete binary tree(完全二叉树).也就是说,整棵binary tree除了最底层的叶节点之外,都是满的.而最底层的叶节点由左至右又不得有空隙. 以上 ...

最新文章

  1. 使用 Smartmontools 检测硬盘坏道
  2. 11.PHP与MySQL
  3. leetcode 328. Odd Even Linked List | 328. 奇偶链表(Java)
  4. kali用x-shell连接_良心国产工具,比Xshell好用还免费!
  5. 20160818_周报日志之二
  6. 数据结构六——堆的应用
  7. android开源2016_Google 2016年开源版本浏览
  8. EXTJS 双层表头 记录
  9. 《Android深度探索》(卷1)HAL与驱动开发 第六章心得体会
  10. SPSS基础操作详解---系统环境设置篇
  11. 最速下降法解析(理解笔记)
  12. 在计算机中 总线简称,微机中的总线一般分为几等
  13. springcloud整合openfeign启动报错,Error creating bean with name ‘feignTargeter‘
  14. TI DSP各种库文件
  15. java 认证框架_java 框架介绍------权限框架
  16. 快递面单成信息泄露重灾区,隐私面单成“必选项”
  17. SCons教程(3) 编译程序
  18. MaxEnt框架下的RL
  19. 论文投稿指南——中文核心期刊推荐(化学)
  20. P014魔改8G显存

热门文章

  1. 对于表单提交的防止重复提交
  2. InnoDB-聚簇索引和MyISAM非聚簇索引
  3. 巨杉数据库v5.0携手迪思杰深化战略级合作
  4. java中new一个对象时具体都发生了什么?
  5. Python实现isPrime()函数,参数为整数,要有异常处理。如果整数是质数,返回True,否则返回False。通过调用isPrime()函数,打印200以内的所有质数,以空格分割。
  6. oracle存储过程入门教程
  7. Dojo 1.6 最新官方教程: Hello Dojo!
  8. Mysql优化_慢查询开启说明及Mysql慢查询分析工具mysqldumpslow用法讲解
  9. Mysql数据库insert报慢查询
  10. 反掩码、掩码和通配符的区别