zoukankan      html  css  js  c++  java
  • heapsort

    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]

    (上根下枝)

  • 相关阅读:
    phpcms基础
    读取数据库有的设置选中状态
    用php 生成 excel 表格
    ajax验证用户名是否存在,手机号是不是匹配
    系统登陆简单的密码验证
    分页显视
    时间选择的三级连动 年,月,日
    session控制登入权限
    jQuery, js 验证两次输了密码的一相同
    正则表达式判断手机号是否11位数字
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6117378.html
Copyright © 2011-2022 走看看