My集合框架第五弹 最小堆
二叉堆(以最小堆为例),其具有结构性质和堆序性质
结构性质: 堆是一棵完全的二叉树,一颗高为h的完全二叉树有2^h到2^h-1个节点,高度为log N
而且该结构可以很容易的使用数组来表示:对于数组中任一位置i上的元素,其左儿子在位置2i上,右儿子在2i+1,其父节点在[x/2]处
堆序性质:在一个堆中,对于每一个节点X,X的父亲中的关键字小于或等于X中的关键字
也就是说:最小元总可以在根处找到
主要的操作为插入和删除:
以数组存储为例,算法在代码中体现:
/**
* 向堆中插入元素x,
* 利用堆的性质,在一个堆中,对于每一个节点X,X的父亲中的关键字都小于或者等于X中的关键字,
* ps根节点除外(根节点没有父节点),时间复杂度为logN
* step1:如果堆没有满,在完全二叉树的下一个位置插入一个空穴
* step2:判断空穴是否存在父节点,如果不存在,直接插入;否则,step3;
* step3:(x.value>=[x/2].value)?step4:step5;
* step4:将X直接放在该空穴,return
* step5:将父节点的值移入空穴中,空穴就朝着根的方向上前进,回到step2;
* @param x
*/
public void insert(Comparable x){
if(cursize == array.length-1){
//堆已经满了,需要重新调整
rebuild();
}
if(cursize==0){
//没有父节点
array[1] = x;
cursize++;
}else{
int temp = ++cursize;
while(temp>1 && x.compareTo(array[temp/2])<0){
//父节点下移
array[temp] =array[temp/2];
temp/=2;
}
//空穴插入
array[temp] = x;
}
}
删除操作:
/**
* 删除堆中的最小元素并返回,方式与插入向反,时间复杂度为logN
* step1:将根节点出视为空穴X
* step2:if(空穴X的左右子树都存在) step3;else if(空穴只存在左子树) step4 ;else step5
* step3:if(空穴的X的左子树2X>X的右子树2X+1) 空穴<-->右子树;else 空穴<-->左子树;finally 继续step2
* step4:空穴和左子树交换,空穴已就位,且满足完全二叉树的要求
* step5:空穴和最后一个元素交换位置
* @return
*/
public Comparable deleteMin(){
if(isEmpty())
return null;
Comparable min = array[1];
int temp = 1;
while(2*temp<=cursize){
if(2*temp+1<=cursize){
//左右子树都存在
if(array[2*temp].compareTo(array[2*temp+1])>0){
array[temp] = array[2*temp+1];
temp = 2*temp+1;
}else{
array[temp] = array[2*temp];
temp = 2*temp;
}
}else{
//只存在左子树
array[temp] = array[2*temp];
temp = 2*temp;
}
}
array[temp] = array[cursize--];
return min;
}
测试代码:
@Test
public void test() {
BinaryHeap heap = new BinaryHeap();
for(int i = 19;i>1;i--){
heap.insert(i);
// heap.printHeap();
}
while(!heap.isEmpty()){
System.out.print(heap.deleteMin()+"\t");
}
}
结果: aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjoAAABdCAIAAAAjRFtcAAAfSUlEQVR4nO2de1RT177v83f3vf3nnDHOPWOcfdt92jG21dteH9t9K6e1t+PseqtnHCrWB9iCCBGpRcRgaRSsUEASpJrqAaMo0G6LqUpIABFFNApCVJTEQhtADYjBgIRHIpD3vH9MElZW1loECYSs/j7jOxgzM2vONd9f5swKcB5oByil1iNKRSak7jhSCQKxRpEJqQggAHMcND/FUT9+Ti06rzpcCQKxRuBVlMBMB81DTduuvjhcAQKxRmBXlMBMB81DcVSPnlOKzq7iv6sAgVgjsCtKYKaD5qE4LY/6KUVvV3IQiDUCu6IEZjpoHorT8rCfUnR2tT1PTlSJOLpEFF4iji4Rx5eU8CUlAolELJFJJLIaSY1CplDJFBpSEtB8U0XuYkoFvGBzILArSrxnOmju9e7G0ICXYV6Jc/9hH6V8tStRuGrYvD1PrjebidqeJ69taMNhmaIr4PUEMahcsMRitZPUWvHF78GxvO1q84Hyt3Y1MGvzgfKAuMicAXY1H7QkdI07/O7GTwNenoCLc7+zj1J0dhV3SEaUWBStGjbHHZJ1q1vahJl3w1a3CTO71S1xh2S1Da16s7nP5VikhKD5ows5S73tqqMura3ii4rcxQEv3qzK267eSry5npvJrLcSbwbEReYM75mOpS7b61bA+47dkkvlb3/8vlwqxy+XhH4U8CIFXJx7nXpK0dnVtkMyokSCaNWw2YlQmzBLl7DddCBNl7C9TZjlQM7a+tY+i7nfYsF2RUq47VCzenJ2mC6XyLwuoFSzmuJiysi5kFD+IIRftmyHOIRfFl1QX9n8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sCuAAAAgCAA7AoAAAAIAsCuAAAAgCAA7AoAAAAIAsCuAAAAgCAA7AoAAAAIAsCuAAAAgCAA7AoAAAAIAsCuAAAAgCAA7AoAAAAIAv4/5cadgYpaDDUAAAAASUVORK5CYII=" alt="" />
好饿啊。。。。。。。。。。。。。。
My集合框架第五弹 最小堆的更多相关文章
- My集合框架第六弹 左式堆
左式堆(Leftist Heaps)又称作最左堆.左倾堆.左式堆作为堆的一种,保留了堆的一些属性. 第1,左式堆仍然以二叉树的形式构建: 第2,左式堆的任意结点的值比其子树任意结点值均小(最小堆的特性 ...
- Java集合框架(五)—— Map、HashMap、Hashtable、Properties、SortedMap、TreeMap、WeakHashMap、IdentityHashMap、EnumMap
Map Map用于保存具有映射关系的数据,因此Map集合里保存着两组值,一组值用于保存Map里的key,另一组值用于保存Map里的value,key和value都可以是任何引用类型的数据.Map的ke ...
- java 集合框架(十五)Deque
一.概述 Deque是Queue的子接口,我们知道Queue是一种队列形式,而Deque则是双向队列,它支持从两个端点方向检索和插入元素,因此Deque既可以支持LIFO形式也可以支持LIFO形式.D ...
- Java源码解析——集合框架(五)——HashMap源码分析
HashMap源码分析 HashMap的底层实现是面试中问到最多的,其原理也更加复杂,涉及的知识也越多,在项目中的使用也最多.因此清晰分析出其底层源码对于深刻理解其实现有重要的意义,jdk1.8之后其 ...
- My集合框架第四弹 HashTable(链表解决冲突)
package com.wpr.collection; import java.util.LinkedList; import java.util.List; public class HashTab ...
- My集合框架第三弹 AVL树
旋转操作: 由于任意一个结点最多只有两个儿子,所以当高度不平衡时,只可能是以下四种情况造成的: 1. 对该结点的左儿子的左子树进行了一次插入. 2. 对该结点的左儿子的右子树进行了一次插入. 3. 对 ...
- 浅谈集合框架五——集合框架扩展:Collections工具类的使用,自定义比较器
最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...
- J.U.C体系进阶(五):juc-collections 集合框架
Java - J.U.C体系进阶 作者:Kerwin 邮箱:806857264@qq.com 说到做到,就是我的忍道! juc-collections 集合框架 ConcurrentHashMap C ...
- 十五、Java基础---------集合框架体系以及List
在介绍集合之前先说一下数组,正如我们所知,数组是某一类型数据的集合,强调的是数据,而且必须单一:集合框架的不同之处在于存储的数据类型没有任何限制,既可以存储基本数据类型(会自动提升为相应的包装类)也可 ...
随机推荐
- CocoStudio UI 编辑器的使用
详细教程:http://www.cocoachina.com/bbs/read.php?tid=161567 Table of Contents 1 游戏中的 UI 1.1 基于 Cocos2d-x ...
- 20160202.CCPP体系详解(0012天)
内容概要:C语言控制语句题库.doc 第三章 控制语句 一.选择题 1. 以下语句中无限循环语句是[B]. A)for(;2&5;); B)while(1,2,3); -> while( ...
- MySQL Database on Azure - 利用PowerShell快速创建使用数据库服务
如果您的应用需要通过脚本快速创建一个或多个MySQL数据库,MySQL Database on Azure目前开放了对于PowerShell的支持,可以帮助您快速利用自动化脚本进行数据库服务的创建.管 ...
- 《C和指针》读书笔记 第2章-基本概念
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936485.html
- Servlet、Struts2、SpringMVC执行流程
Servlet 有以下四个阶段: 1.加载和实例化 Servlet容器负责加载和实例化Servlet. 当Servlet容器启动时,或者在容器检测到需要这个Servlet来响应第一个请求时,创建Ser ...
- 对JAVA集合进行遍历删除时务必要用迭代器
java集合遍历删除的方法: 1.当然这种情况也是容易解决,实现方式就是讲遍历与移除操作分离,即在遍历的过程中,将需要移除的数据存放在另外一个集合当中,遍历结束之后,统一移除. 2.使用Iterato ...
- 转载:50个C/C++源代码网站
来源:http://www.cnblogs.com/feisky/archive/2010/03/05/1679160.html C/C++是最主要的编程语言.这里列出了50名优秀网站和网页清单,这些 ...
- Visual Studio下Qt调用IDL
一.简单介绍: 1.ActiveQt包含QAxContainer和QAxServer组件. 1) QAxContainer允许使用COM对象,并且可以将ActiveX控件嵌入到Qt程序中去. QAxC ...
- 在VMware虚拟机中安装CentOS 7
[声明] 欢迎转载,但请保留文章原始出处 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3917 ...
- python 数字和字符串转换问题
一.python中字符串转换成数字 (1)import string tt='555' ts=string.atoi(tt) ts即为tt转换成的数字 转换为浮点数 string.atof(tt) ( ...