zoukankan      html  css  js  c++  java
  • Chpater 10: Sorting

    Internal Sort:

    Bubble      O(n2)

    Selection     O(n2)

    Insertion    O(n2)

    Shell      O(nlogn)

    Merge      O(nlogn)

    Heap      O(nlogn)

    Quick Sort    O(nlogn)

    Tree Sort(BST)  O(nlogn)

    Linear Sorting:

    Counting Sort    O(n)

    BUcket Sort    O(n)

    Radix Sort    O(n)

    External Sorting:

    K chunks of data need to be sorted and a K-way merge has to be completed.     Assembly Line

    Problems:

    pro22: Nearly Sorted.  Given a array of n elements, each which is at most K positions from its target position, devise an algorithm that sort in O(nlogK).

    Insert the first K elements into a binary heap of size K. Insert the next element from the array into the heap, and delete the minimum element from the heap.

    pro35: Nuts and Bolts. We are given a box which contains bolts and nuts. Assume that there are n nuts and n bolts and that each nut matches exactly one bolt. By trying to match a bolt and a nuts we can see which one is bigger, but we cannot compare two bolts or two nuts directly.

    We can use divide-and-conquer to solve. Pick a random bolt B[i], Using this bolt to rearrange the array of nuts into three groups of elements:

    •   Nuts smaller than B[i]
    •   Nuts matches B[i]
    •   Nuts larger than B[i]
  • 相关阅读:
    用Springboot写一个只有一个条件的复杂查询
    Springboot The requested profile "pom.xml" could not be activated because it doesn't not exists
    springboot配置路径
    vuex
    @MappedSuperclass的作用
    icon.css
    default.html
    WebService调用
    通用分页存储过程
    存储过程获得最新订单号
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3508143.html
Copyright © 2011-2022 走看看