Tuesday, July 10, 2018

MIT 6.00 コンピュータサイエンス秋期講座中間試験その1

MIT 6.00 コンピュータサイエンス秋期講座中間試験その1

オープンコースウエア 大学名:MIT
講座名:6.00 Introduction to Computer Science and Programming
講義日:2008年10月2日(木曜日) ― 第5週・2回目
担当教授:Prof. Eric Grimson


第5週2回目の講義で、はじめての中間試験。実際に使われたテスト問題ではないけれど、模擬試験内容がアップされています。
中間模擬試験の一部を下に書き出して、実際に解いてみることにします。プラス、なぜそう考えたか自分なりの考えも回答の横に追加しておきます。


(原本)
1) Are each of the following True or False:
1.1. Any program that can be written using only function definitions and calls, the
basic arithmetic operators, assignment, and conditionals will run in constant time.
1.2. Newton’s method will always converge on a correct root of a function.
1.3. In Python, dictionaries are immutable.
1.4. The value of ‘math.sqrt(2.0)*math.sqrt(2.0) == 2.0’ is True.
1.5. One should always avoid iteration when a recursive solution is possible.
1.6. Typically, the use of functions in a program reduces the total number of lines
of code.
1.7. In Python, retrieving the value associated with a dictionary key takes roughly
constant time


(妙訳)
1.以下の設問に対し、True もしくは False で答えよ。
1.1 どのようなプログラムでも、関数定義、呼び出し、基本的な四則演算(加減乗除)、アサイメント、および条件式だけから書くことができる。
1.2 ニュートン法を用いて解を求めると、かならず正しい平方根の値に収束する。
1.3 Pythonでは、dictionary 関数は、immutable(要素不変)である。
1.4 等式 math.sqrt(2.0)*math.sqrt(2.0) == 2.0 は正しい。
1.5 再帰法で問題が解ける場合は、ループ(iteration)の使用を常に避けるべきである。
1.6 関数(Function)をプログラムに実装する意義は、コードの総行数を減らすことにある。
1.7 Python で、dictionary keyにひも付いた値を呼び出す時間は、ほぼ一定である。


私の回答
1.1 False ‐ 自己完結性(関数定義、呼び出し、基本的な四則演算、アサイメント、および条件式)を備えたチューリング機械でどんなプログラムをかけるというわけではないから。
1.2  False ‐ ニュートン法を適用する方程式(曲線)により、必ずしも収束するわけではない。
1.3  False ‐ dictionary 関数は、Listを使っているはずで、Listはmutableだから。immutable・要素不変は、Tuple)
1.4  False ‐ math.sqrt(2.0)の値は誤差を含んでいるため。
1.5  False ‐ 再帰法は、必ずしも収束するわけではない。無限ループに入り込む可能性もある。
1.6  False ‐ コードの総行数を減らすより、むしろデザインのモジュール化ではないか?
1.7  True ‐ ハッシュ関数を使用しているため値を呼び出す時間は、ほぼ一定。
正答
1.1 False
1.2  False
1.3  False
1.4  False
1.5  False
1.6  True (code reuse)
1.7  True

No comments:

Post a Comment

MIT 6.00 コンピュータサイエンスとプログラミング秋期講座第2回

  MIT 6.00 コンピュータサイエンスとプログラミング秋期講座第2回 オープンコースウエア 大学名:MIT 講座名:6.00 Introduction to Computer Science and Programming Download course material ...