跳到主要内容
Z

选择排序可视化工具

以动画方式演示选择排序(Selection Sort),提供逐步执行、速度调节、自定义输入数据、实时的比较/交换计数器以及伪代码展示。完全在浏览器本地运行。

免费 无需注册 客户端运行 注重隐私 Updated
/
Comparisons: Swaps / writes: Array accesses:

Code examples

Ready-to-copy reference implementations. Free to use in your own projects and assignments.

使用方法

  1. 1 点击“播放”查看每一轮如何扫描找出最小值并将其交换到正确位置。
  2. 2 使用“单步”按逐次比较的方式前进,观察算法如何跟踪当前最小值。
  3. 3 在“自定义输入”框中输入你自己的数字,然后点击“应用”。
  4. 4 实时查看高亮显示的伪代码,以及比较次数/交换次数的计数器。

为什么使用此工具

  • 直观看到每一轮如何选出剩余元素中的最小值并将其放到最前面。
  • 发现该算法执行的比较次数始终相同,与输入数据的顺序无关。
  • 各项统计数据说明了为什么该算法最多只交换 n−1 次——在写操作成本较高的场景下非常有用。
  • 完全在浏览器本地运行,无需注册,无需上传数据。

常见问题

什么是选择排序?

选择排序将数组分为两部分:已排序区域和未排序区域。每一轮都会扫描未排序部分找出最小值,然后将其交换到已排序边界处。

选择排序的时间复杂度是多少?

在所有情况下(最好、平均和最坏)都是 O(n²),因为查找最小值的扫描过程始终需要遍历所有剩余元素。

选择排序是稳定的吗?

不稳定。将最小值跨越较远距离进行交换,可能导致某个元素越过与其值相同的另一个元素,从而改变它们的相对顺序。不过,基于链表的变体可以做到稳定。

选择排序在什么情况下有用?

当需要尽量减少写操作次数时非常有用——该算法最多只执行 n−1 次交换,远少于冒泡排序。除此之外的情况,通常更推荐使用插入排序。

什么是 选择排序可视化工具?

选择排序可视化工具演示了选择排序算法如何在未排序区域中不断查找最小值,然后将其交换到已排序边界。该工具直观展示了为什么该算法总是需要 O(n²) 次比较,但交换次数最多只有 n−1 次。

功能特性

Step-by-step animation

Watch the minimum get found and swapped to the front each pass.

Complexity

Time: O(n²) in all cases. Space: O(1). In-place; not stable. Only O(n) swaps.

100% private

Runs entirely in your browser — nothing is uploaded.

示例

Input

[64, 25, 12, 22]

Output

select 12 → [12,25,64,22]; 22 → [12,22,64,25]; 25 → [12,22,25,64] (sorted)

常见使用场景

  1. 1

    Learn selection logic

    See why the comparison count is fixed at ~n²/2 regardless of input.

  2. 2

    Minimize writes

    Understand where selection sort helps when swaps/writes are costly.

  3. 3

    Contrast with insertion sort

    Compare its fixed O(n²) against insertion sort's best-case O(n).

概要

Zerethon's selection sort visualizer animates the algorithm in your browser, repeatedly selecting the minimum of the unsorted region and swapping it into place. Selection sort always runs in O(n²) time (best, average, and worst are identical) with O(1) extra space; it is in-place but not stable. It minimizes the number of swaps (O(n)).

分类
算法
价格
免费
隐私
基于浏览器
注册
无需

References

隐私

除非另有说明,否则你的数据永远不会离开浏览器。选择排序可视化工具 完全在客户端运行 — 无需上传服务器,不记录日志,不追踪你输入的内容。

刚接触?阅读包含 Big-O 分析的分步讲解: 了解 Sorting Algorithms →

相关工具

在 Zerethon Social 上创作、分享与成长

免费注册。赚取积分,收集成就,与全球创作者建立联系。

免费试用 Zerethon