Introduction to Algorithms Third Edition

The (binary) heap data structure is an array object that we can view as a
nearly complete binary tree (see Section B.5.3), as shown in Figure 6.1. Each
node of the tree corresponds to an element of the array. The tree is com-
pletely filled on all levels except possibly the lowest, which is filled from the
left up to a point. An array A that represents a heap is an object with two at-
tributes: A: length, which (as usual) gives the number of elements in the array, and
A: heap-size, which represents how many elements in the heap are stored within
array A. That is, although AŒ1 : : A: length may contain numbers, only the ele-
ments in AŒ1 : : A: heap-size, where 0 Ä A: heap-size Ä A: length, are valid ele-
ments of the heap. The root of the tree is AŒ1, and given the index i of a node, we
can easily compute the indices of its parent, left child, and right child:

indiex indices 下标

For the heapsort algorithm, we use max-heaps. Min-heaps commonly imple-
ment priority queues, which we discuss in Section 6.5.

最小堆通常用于构造优先队列。

the largest element in a max-heap is stored at the root, and the subtree rooted at a node contains6.1 Heaps 153
values no larger than that contained at the node itself. A min-heap is organized in the opposite way.

a max-heap
A[PARENT(i)]>=A[i] a min-heap
A[PARENT(i)]<=A[i]

(上根下枝)

heapsort的更多相关文章

  1. Java演算法之堆排序(HeapSort)

    import java.util.Arrays; publicclass HeapSort { inta[]={49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,9 ...

  2. HeapSort 堆排序 基于伪代码实现

    此文原创, http://www.cnblogs.com/baokang/p/4735431.html ,禁止转载 GIF 动态图 伪代码 /* From Wikipedia, the free en ...

  3. 堆排序 Heapsort

    Prime + Heap 简直神了 时间优化好多,顺便就把Heapsort给撸了一发 具体看图 Heapsort利用完全二叉树+大(小)顶锥的结构每次将锥定元素和锥最末尾的元素交换 同时大(小)顶锥元 ...

  4. HeapSort自己yy-未完成

    #include <iostream> #include <cstdio> using namespace std; ; int a[maxn]; int HeapSize; ...

  5. [转载]堆排序(HeapSort) Java实现

    堆排序的思想是利用数据结构--堆.具体的实现细节: 1. 构建一个最大堆.对于给定的包含有n个元素的数组A[n],构建一个最大堆(最大堆的特性是,某个节点的值最多和其父节点的值一样大.这样,堆中的最大 ...

  6. 排序算法FOUR:堆排序HeapSort

    /** *堆排序思路:O(nlogn) * 用最大堆,传入一个数组,先用数组建堆,维护堆的性质 * 再把第一个数与堆最后一个数调换,因为第一个数是最大的 * 把堆的大小减小一 * 再 在堆的大小上维护 ...

  7. 算法导论学习-heapsort

    heap的定义:如果数组a[1,....n]满足:a[i]>a[2*i] && a[i]>a[2*i+1],1<=i<=n/2,那么就是一个heap,而且是ma ...

  8. 排序算法——QuickSort、MergeSort、HeapSort(C++实现)

    快速排序QuickSort template <class Item> void quickSort (Item a[], int l, int r) { if (r<=l) ret ...

  9. Heapsort 堆排序算法详解(Java实现)

    Heapsort (堆排序)是最经典的排序算法之一,在google或者百度中搜一下可以搜到很多非常详细的解析.同样好的排序算法还有quicksort(快速排序)和merge sort(归并排序),选择 ...

随机推荐

  1. cf 559a **

    题意:给一个六边形,求小三角形个数 #include<cstdio> #include<iostream> #include<algorithm> #include ...

  2. Android调用WebService(转)

    Android调用WebService WebService是一种基于SOAP协议的远程调用标准,通过 webservice可以将不同操作系统平台.不同语言.不同技术整合到一块.在Android SD ...

  3. Android Inflate

    inflate就相当于将一个xml中定义的布局找出来. 三种方式可以生成LayoutInflater: LayoutInflaterinflater=LayoutInflater.from(this) ...

  4. POJ1236 - Network of Schools tarjan

                                                     Network of Schools Time Limit: 1000MS   Memory Limi ...

  5. 利用windbg探索进程和进程上下文

    1.列出所有活动进程 使用!process命令可以打印出活动进程的信息.第一个参数是要打印的EPROCESS的地址,如果指定为0则表示打印所有的进程.第二个参数用于说明打印进程信息的详细级别.指定0则 ...

  6. 字符编码GB2312、GBK、UTF-8的区别

    本文来自:javaeye网站 UTF8是国际编码,它的通用性比较好,外国人也可以浏览论坛 GBK是国家编码,通用性比UTF8差,不过UTF8占用的数据库比GBK大~ 提示:如果您的网站客户群体主要是面 ...

  7. tcp的三次握手及四次挥手(连接与中断流程)

    连接的三次握手: 1握.client向server发送连接请求,发送的报文是:syn=1,seq number=生成的随机数x .  这时client的状态是SYN_SEND 2握.server从sy ...

  8. PDA移动POS开单扫描打票收银系统-带来零售批发 新的技术 新的手段!!

    手持POS终端高清彩屏,清晰.美观.大方,适用于仓库.超市.服装.食品.批发零售.手机电脑等企业管理.可与管理软件灵活对接.1:员工记不住价格,产品名称,只要有PDA扫描,价格,库存,直接开销售单,打 ...

  9. BZOJ3290 : Theresa与数据结构

    CANCEL操作可以看作删点,X坐标可以离散化 将询问按Z坐标差分,转化成两个求Z<=某个数的和的询问 将操作CDQ分治 每次将前一半的修改.后一半的查询按照Z坐标排序 然后扫描线,每到一个询问 ...

  10. CentOS 实现自动登陆

    1. 在ssh-client一边使用ssh-keygen生成一对rsa key $ssh-keygen -t rsa 2. 在ssh-client一边使用ssh-add将刚生成的private key ...