Trace, diagnose and repair algorithms
実行順でトレースする
質問で指定された文または反復後の値を記録せよ。未変更の値はそのまま持ち越す。最終答えに直接飛ぶのではなく、トレーステーブルがたどった経路を記録すること。
反例を使って欠陥を見つける
ゼロで初期化された最大値アルゴリズムは正のデータに対して機能するように見える。最も小さな反例は単一の負の値である。既知:答えはデータのメンバーでなければならない。したがって、最初の商品から初期化し、残りの商品を比較する。
DECLARE Best, Value : INTEGER
Best ← -8
Value ← -2
IF Value > Best THEN
Best ← Value
ENDIF
OUTPUT Best
よくあるミス
- 最終的な値のみを埋めている。表には発生順に各変化を示すべきである。
- 誤った行で変数を更新している: 値は割り当てが行われた行で変わり、次の
OUTPUTではない。 - 行は修正したが原因を述べていない。「0 を Data[1] に変更した」よりも、「0 はすべての負の値より大きいため、置き換えられなかった」の方が高い得点となる。
- 修正後に反例のみ进行测试。修正が正常なケースを破損していないよう、通常のケースでも再実行する。
エラーの種類を区別する
構文エラーは言語の構造を破損させ、実行時エラーは実行中に発生する(例:境界外のインデックス)、ロジックエラーは正常に実行しても誤った結果を生む。欠陥を修正した後、反例と通常ケースをテストし、変更された行だけでなく原因も説明せよ。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Best starts at 8. Process values 5, 7, 2, replacing Best only when a value is smaller. Give Best after each value.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
The starter finds the largest of NumberOfValues values but wrongly outputs zero for all-negative data. Correct it. NumberOfValues is 1 to 5.
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
The program executes without crashing but skips the last array item because its loop ends at NumberOfValues - 1. Is this a syntax, runtime or logic error? Enter one word.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
このブラウザでの今回のセッションに保存されました。ご自身または教師で確認してください。これらの説明は自動採点されません。
これらの基準に基づいて説明内容を確認する
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.