作业帮 > 综合 > 作业

算法导论翻译类似于归纳算法算法导论第二章中的原文是:We state these properties of A[1 ¨

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/09/14 08:19:20
算法导论翻译
类似于归纳算法
算法导论第二章中的原文是:We state these properties of A[1 ¨ j -1] formally as a loop invariant.其中举的例子是插入排序,每次循环从数组A中取出第j个元素插入有序区A[1 .. j-1],然后递增j.这样A[1 .. j-1]的有序性始终得到保持,这就是所谓的“循环不变”了.
这个概念主要用来检验算法的正确性.
原文如下:We use loop invariants to help us understand why an algorithm is correct. We must show three things about a loop invariant:
Initialization: It is true prior to the first iteration of the loop.
Maintenance: If it is true before an iteration of the loop, it remains true before the next iteration.
Parameters are passed to a procedure by value: the called procedure receives its own copy of the parameters, and if it assigns a value to a parameter, the change is not seen by the calling procedure. When objects are passed, the pointer to the data representing the object is copied, but the object's fields are not. For example, if x is a parameter of a called procedure, the assignment x ← y within the called procedure is not visible to the calling procedure. The assignment f [x] ← 3, however, is visible.
求计算机专业人员的翻译 不太了解这个procedure 是翻译为“函数”吗?
以上提问有误: 仅一下这一段:
Parameters are passed to a procedure by value: the called procedure receives its own copy of the parameters, and if it assigns a value to a parameter, the change is not seen by the calling procedure. When objects are passed, the pointer to the data representing the object is copied, but the object's fields are not. For example, if x is a parameter of a called procedure, the assignment x ← y within the called procedure is not visible to the calling procedure. The assignment f [x] ← 3, however, is visible.
求计算机专业人员的翻译 不太了解这个procedure 是翻译为“函数”吗?
个人理解这个procedure 应该是指代码的执行过程,每一行代码其实都可以看做是一个procedure
以Java为例,如果有如下代码:
int x = 5;
int y = 3;
int z;
z= x + y;
按照文意,参数(我觉得这里就差不多是变量的意思)是以其数值在代码执行中进行传递的: 调用某一变量的代码执行过程 z = x + y 获得的只是 x 和 y 的副本, 如果一段代码执行给某一变量赋值, 这一变化是不能被调用x 和y 的z = x + y看到的, 当一个对象被传值的时候, 这个对象在内存中是不变的,只不过是复制了一个指向这个对象的指针而已.
当z= x + y执行时, z= x + y是不管x和y怎样的,它只知道需要指针分别指向X和Y 在内存中的位置, 而如果是x = 3 的话, 因为3是具体数值而不是另一个变量,因此这里对x的赋值就是“可见”了
以上是我的一点拙见,只是我个人的理解,请楼主谨做参考