zoukankan      html  css  js  c++  java
  • Sort

    Counting Sort

     

    1. Counting Sort doesn't work for negative number.

    2. Counting Sort assumes that each element is SMALL INTEGER.

    3. Time Complexity is O(Maximum value - Minimum value).

    4. It is useful when the difference is not large

    Algorithm:

    1. Create an array of the size of the Maximun Value + 1.

    2. Count each element.

    3. Add up all elements.

    4. Put them back to the result.

    https://www.youtube.com/watch?v=o3FUC6l89tM

    Radix Sort

     

    1. When we are sorting the numbers we will first find the number of digits in the biggest number.

    2. If there are N digits in the biggest number then we will need to perform N number of pass.

    3. We will pad the remaining numbers with leading zeros so they all have N digits.

    4. Then we will take 10 buckets labeled 0 to 9 and sort the numbers.

    Time Complexity : O(N*n)  where N is the digits of the biggest number, and n is the length of the array.

    Space Complexity: O(1), it will take 10 buckets.

    https://www.youtube.com/watch?v=YXFI4osELGU

    Bucket Sort

     

    1. Setup an array of initially empty "buckets".

    2. Scatter: Traverse the original array and extract each element into its bucket.

    3. Sort each non-empty buckets (With each bucket Heapified).

    4. Visit the buckets and put them back in order.

    https://www.youtube.com/watch?v=aaKNtxHgaq4

    Selection Sort

    https://www.youtube.com/watch?v=BSXIolKg5F8

    Insertion Sort

    https://www.youtube.com/watch?v=-Z00it6Nkz8

    Bubble Sort

    https://www.youtube.com/watch?v=llX2SpDkQDc

  • 相关阅读:
    [BZOJ1415]聪聪和可可
    [POJ2096]Collecting Bugs
    开博第一天
    实现CSS样式垂直水平完全居中
    Vue中独立组件之间数据交互
    python Template中substitute()的使用
    eclipse 编辑 python 中文乱码的解决方案
    java Math.random()随机数的产生
    java文件读写的两种方式
    My way on Linux
  • 原文地址:https://www.cnblogs.com/winscoder/p/4298114.html
Copyright © 2011-2022 走看看