• 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]
  • 相关阅读:
    网址收藏
    Linux创建swap文件
    vim命令大全
    char * 和字符数组
    JSR 203终于要出来啦
    对象关系技术的探讨
    最近编码更流畅了
    孤独终止的地方,就是广场开始的地方......
    不要奢望.NET能够跨平台
    实现了HTTP多线程下载
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3508143.html
Copyright © 2020-2023  润新知