程序包含 2 个嵌套循环,其中包含 4 个 if 条件。有多少条路?

发布于 2024-09-01 02:40:30 字数 235 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2024-09-08 02:40:30

如果每个循环恰好执行 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 fixed 20*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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文