algo Computer Science

6 个科学问题 · 计算机 Computer Science

本页目录

贪心算法适合什么样的问题?

What kind of problems suit greedy algorithms?

当问题具备最优子结构和贪心选择性质(即局部最优能推出全局最优)时,贪心算法高效且简单,例如霍夫曼编码、最小生成树的 Kruskal;否则需要动态规划。
Greedy works when a problem has optimal substructure and the greedy-choice property (local optima lead to a global optimum), e.g. Huffman coding or Kruskal; otherwise use DP.
难度 专业 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#算法 #优化

什么是稳定的排序算法?

What is a stable sorting algorithm?

稳定排序保证相等键的元素在排序后保持原有相对顺序,便于多关键字依次排序(如先按日期再按名称);归并排序、插入排序稳定,快排、堆排序通常不稳定。
A stable sort keeps equal-key elements in their original relative order, enabling multi-key sorting (e.g. date then name); merge and insertion sort are stable, quicksort and heapsort usually are not.
难度 专业 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#排序 #算法

Dijkstra 算法如何求最短路径?

How does Dijkstra's algorithm find shortest paths?

Dijkstra 用优先队列反复取出当前距离最小的未访问节点,松弛其邻居的距离,要求边权非负;时间复杂度依赖堆实现为 O((V+E) log V)。
Dijkstra repeatedly extracts the unvisited node with the smallest distance and relaxes its neighbors, requiring non-negative weights; with a heap it runs in O((V+E) log V).
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#图 #最短路径

动态规划的核心思想是什么?

What is the core idea of dynamic programming?

动态规划通过把问题拆成重叠子问题,用记忆化或填表避免重复计算,并把最优解构建在子问题最优解之上,典型应用有背包、最长公共子序列等。
Dynamic programming breaks a problem into overlapping subproblems solved once and reused, building the optimal solution from optimal sub-solutions, as in knapsack or longest common subsequence.
难度 进阶 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#算法 #优化

快速排序的基本思想是什么?

What is the basic idea of quicksort?

快排选一个基准值把数组分区为小于和大于基准的两部分,再对两区递归排序;平均 O(n log n),最坏退化为 O(n²),常用随机化基准来避免最坏情况。
Quicksort picks a pivot, partitions the array into smaller and larger parts, then recursively sorts them; average O(n log n), worst O(n²), often avoided via randomized pivots.
难度 进阶 · 适合 幼儿(3-6) CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#排序 #分治

二分查找是怎么工作的?

How does binary search work?

在已排序数组中,二分查找每次取中点与目标比较,丢弃一半区间,重复直到找到或区间为空,时间复杂度 O(log n)。
On a sorted array, binary search compares the midpoint to the target and discards half the range each step, repeating until found or empty, in O(log n) time.
难度 入门 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source

Cormen, Leiserson, Rivest, Stein,《Introduction to Algorithms》第3版,MIT Press,2009

T. H. Cormen et al., Introduction to Algorithms, 3rd ed., MIT Press, 2009

#查找 #算法