Joe*_*ruz 16 algorithm terminology definition
简单的问题但是,在引用数字范围时,我看到了排他性和包容性.
例如,这是算法书中的一行:
以下函数打印从1到n(含)的2的幂.
这是什么意思?什么使数字范围包容或排他?
Rak*_*111 33
在计算机科学中,包容性/排他性不适用于算法,而是适用于数字范围(更具体地说,适用于范围的端点):
1 through 10 (inclusive)
1 2 3 4 5 6 7 8 9 10
1 through 10 (exclusive)
1 2 3 4 5 6 7 8 9
Run Code Online (Sandbox Code Playgroud)
在数学中,上面的2个范围是:
[1, 10]
[1, 10)
Run Code Online (Sandbox Code Playgroud)
你可以很容易地记住它:
Tim*_*sen 19
以下函数打印从1到n(含)的2的幂.
这意味着该函数将计算2^i在哪里i = 1, 2, ..., n,换句话说,i可以具有从1到包括该值的值n.即n 包含在包含中
另一方面,如果你的书说:
以下函数打印从1到n(不包括)的2的幂.
这意味着i = 1, 2, ..., n-1,即i可以采取值高达N-1,但不包括n,这意味着i = n-1是它可以have.ie n中的最高值被排除在排斥.
简单来说,包含是指在该数之内n,而排除是在该数之内和之外n。
注意:每个论点都应标记其“clusivity”/“participation”
# 1 (inclusive) through 5 (inclusive)
1 <= x <= 5 == [1, 2, 3, 4, 5]
# 1 (inclusive) through 5 (exclusive)
1 <= x < 5 == [1, 2, 3, 4]
# 1 (exclusive) through 5 (inclusive)
1 < x <= 5 == [2, 3, 4, 5]
# 1 (exclusive) through 5 (exclusive)
1 < x < 5 == [2, 3, 4]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35569 次 |
| 最近记录: |