[英]Summation of Selection Sort
I'm working through the algorithm design manual and stuck on understanding the summation behind selection sort in Chapter 2.我正在阅读算法设计手册,并坚持理解第 2 章中选择排序背后的总和。
Can someone explain how this summation is simplifed?有人可以解释这个总结是如何简化的吗? For example, How do we get to n - i - 1?
例如,我们如何得到 n - i - 1?
if n = 8, then s(n) is (8 - 1) + (8 - 2) + (8 - 3) etc. What does the result of this mean in relation to the formula?如果 n = 8,则 s(n) 为 (8 - 1) + (8 - 2) + (8 - 3) 等。与公式相关的结果是什么? I've included a screenshot of the paragrah and my notes for context.
我已经包含了段落的屏幕截图和我的上下文注释。 screenshot of selection sort
选择排序截图
\sum_{i=0}^{j-1} \sum_{j=i+1}^{n-1} 1 = \sum_{i=0}^{j-1} n - i - 1
, why this, where isj
?\sum_{i=0}^{j-1} \sum_{j=i+1}^{n-1} 1 = \sum_{i=0}^{j-1} n - i - 1
,为什么这个,j
在哪里?
You were asking about the simplifying step with which the index j
is summed over.您在询问对索引
j
求和的简化步骤。 This link goes more in detail, but in general,这个链接更详细,但总的来说,
\sum_{j=u}^{v} 1 = -u + v + 1
is equivalent to this pseudo-code,相当于这个伪代码,
sum = 0
for(int j = u; j <= v; j++)
sum += (f(j) = 1)
return sum
For example, with u=3
and v=22
, it would be sum = u - v + 1 = 22 - 3 + 1 = 20
.例如,对于
u=3
和v=22
,它将是sum = u - v + 1 = 22 - 3 + 1 = 20
。
With -u + v + 1
at u = i+1
and v = n-1
it simplifies to -(i+1) + (n-1) + 1 = n - i - 1
.在
u = i+1
和v = n-1
处使用-u + v + 1
1 它简化为-(i+1) + (n-1) + 1 = n - i - 1
。
if
n=8
does\sum_{i=0}^{n-1} n - i - 1
refer to(8-1) + (8-2) + (8-3) + ... + 2 + 1 [+ 0]
, why two different kinds of values?如果
n=8
确实\sum_{i=0}^{n-1} n - i - 1
指的是(8-1) + (8-2) + (8-3) + ... + 2 + 1 [+ 0]
,为什么有两种不同的值?
It has been simplified from (8-0-1) + (8-1-1) + (8-2-1) + ... (8-5-1) + (8-6-1) + (8-7-1)
.它已简化为
(8-0-1) + (8-1-1) + (8-2-1) + ... (8-5-1) + (8-6-1) + (8-7-1)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.