第二、四章一些问题

42 views
Skip to first unread message

suzhiyang

unread,
Jun 6, 2010, 10:20:29 AM6/6/10
to cs501pku
闫老师:
您好!
 
第二章(P68):
8. Q: Consider an unstructured overlay network in which each node randomly 
chooses c neighbours. If P and Q are both neighbours of R, what is the 
probability that they are also neighbours of each other? 
A: Consider a network of N nodes. If each node chooses c neighbours at 
random, then the probability that P will choose Q, or Q chooses P is roughly 
2c/(N-1). 
这个概率是怎么算出来的??
 
第四章(P176):
4. Q: Consider a procedure incr with two integer parameters. The procedure 
adds one to each parameter. Now suppose that it is called with the same 
variable twice, for example, as incr(i, i). If i is initially 0, what value 
will it have afterward if call-by-reference is used? How about if 
copy/restore is used? 
A: If call by reference is used, a pointer to i is passed to incr. It will 
be incremented two times, so the final result will be two. However, with 
copy/restore, i will be passed by value twice, each value initially 0. Both 
will be incremented, so both will now be 1. Now both will be copied back, 
with the second copy overwriting the first one. The final value will be 1, 
not 2.  
若是前者,那么返回值是(2,2)。若是后者,因为是值传送,每个值都被初始化为0,然后每个值都加1,变为(1,1)。最后这两个值都被复制回来,结果是(1,1)。红字部分是什么意思?
 
谢谢!
 
2010-06-06

suzhiyang

Hongfei Yan

unread,
Jun 6, 2010, 11:09:08 AM6/6/10
to cs501pku
chapter 2:
8. P选择Q的概率是c/(N-1). Q选择P的概率也是c/(N-1)。所以是2c/(N-1).

chapter 4:
4. 两个参数都是i,如果是copy/restore,则后一个i的返回值会覆盖前一个i的返回值。
Reply all
Reply to author
Forward
0 new messages