Git Product home page Git Product logo

Comments (1)

Snailclimb avatar Snailclimb commented on June 1, 2024

O(n^2)

好的,顺便重新整理了一个表格:

排序算法 时间复杂度(平均) 时间复杂度(最差) 时间复杂度(最好) 空间复杂度 排序方式 稳定性
冒泡排序 O(n^2) O(n^2) O(n) O(1) 内部排序 稳定
选择排序 O(n^2) O(n^2) O(n^2) O(1) 内部排序 不稳定
插入排序 O(n^2) O(n^2) O(n) O(1) 内部排序 稳定
希尔排序 O(nlogn) O(n^2) O(nlogn) O(1) 内部排序 不稳定
归并排序 O(nlogn) O(nlogn) O(nlogn) O(n) 外部排序 稳定
快速排序 O(nlogn) O(n^2) O(nlogn) O(logn) 内部排序 不稳定
堆排序 O(nlogn) O(nlogn) O(nlogn) O(1) 内部排序 不稳定
计数排序 O(n+k) O(n+k) O(n+k) O(k) 外部排序 稳定
桶排序 O(n+k) O(n^2) O(n+k) O(n+k) 外部排序 稳定
基数排序 O(n×k) O(n×k) O(n×k) O(n+k) 外部排序 稳定

术语解释

  • n:数据规模,表示待排序的数据量大小。
  • k:“桶” 的个数,在某些特定的排序算法中(如基数排序、桶排序等),表示分割成的独立的排序区间或类别的数量。
  • 内部排序:所有排序操作都在内存中完成,不需要额外的磁盘或其他存储设备的辅助。这适用于数据量小到足以完全加载到内存中的情况。
  • 外部排序:当数据量过大,不可能全部加载到内存中时使用。外部排序通常涉及到数据的分区处理,部分数据被暂时存储在外部磁盘等存储设备上。
  • 稳定:如果 A 原本在 B 前面,而 $A=B$,排序之后 A 仍然在 B 的前面。
  • 不稳定:如果 A 原本在 B 的前面,而 $A=B$,排序之后 A 可能会出现在 B 的后面。
  • 时间复杂度:定性描述一个算法执行所耗费的时间。
  • 空间复杂度:定性描述一个算法执行所需内存的大小。

from javaguide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.