程序包含 2 个嵌套循环,其中包含 4 个 if 条件。有多少条路?
在 Roger Pressman 的书中,有一个示例描述了一个具有 2 个嵌套循环的程序,内部循环包含四个 if 语句。这两个循环最多可以执行 20 次。他表示这会产生大约 10^14 条路径。为了得到这么大的数字,循环内的路径似乎要乘以 2^40,即 2^20 乘以 2^20,以考虑通过两个循环的所有可能性。我不明白为什么这个系数不只是 400,即 20 乘以 20。有人可以解释一下吗?如果您有 ppt 幻灯片并且可以看到程序图,将会有所帮助。谢谢。
In Roger Pressman's book, there is an example described of a program with 2 nested loops, the inner loop enclosing four if statements. The two loops can execute up to 20 times. He states that this makes about 10^14 paths. To get a number this large, it seems the paths inside the loops are multipllied by 2^40, i.e. 2^20 times 2^20 to account for all the possibilities of going through the two loops. I can't see why this factor is not just 400, i.e. 20 times 20. Can someone shed some light? It will help if you have the ppt slides and can see the program graph. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果每个循环恰好执行 20 次,则内部块将乘以
20*20
,因为内部块将通过固定的20*20< /code> 次,重要的是每次通过它的路径。您说它们执行“最多 20 次”,因此如果内部执行 19 次、18 次等,则需要考虑控制流更改,然后外部执行相同
The inner block would be multiplied by
20*20
if the loops execute exactly 20 times each, since the inner block would be run through a fixed20*20
times, and all that would matter is the path through it each time. You said they execute "up to 20 times", so you need to account for control flow changes if the inner one executes 19 times, 18 times, etc., and then the same for the outer one