【发布时间】:2009-09-22 21:52:17
【问题描述】:
我有一个计算机程序,它读取以后缀表示法编写的操作数和运算符的字符数组。然后程序扫描数组,使用堆栈计算结果,如下所示:
get next char in array until there are no more
if char is operand
push operand into stack
if char is operator
a = pop from stack
b = pop from stack
perform operation using a and b as arguments
push result
result = pop from stack
我如何通过归纳证明这个程序正确地计算任何后缀表达式? (取自练习 4.16 Java 算法(Sedgewick 2003))
【问题讨论】:
-
这与标准归纳有何不同?证明基本情况,然后假设大小为 n-1 的情况为真,这意味着情况 n 为真。这是关于归纳时必须做的事情的简要总结。
-
我遇到的问题是找出基本情况和归纳步骤是什么。基本情况是 n = 3,数组是:操作数操作数运算符,我如何证明上面的程序计算正确?
标签: math proof postfix-notation induction