Algorithmic Efficiency
導入済み
9:10
アルゴリズムとプログラミング
1百万名の名前が入った電話帳を想像し、その中から1人を見つける必要があるとしよう。一つずつ確認していくと、一日中かかってしまうかもしれない。約…で見つける方法がある。
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| Algorithmic efficiency/ˌælɡəˈrɪθmɪk ɪˈfɪʃənsi/ | アルゴリズム効率 |
| slow/sləʊ/ | 遅い |
| steps/steps/ | 手順 |
| reasonable/ˈriːzənəbl/ | 妥当な |
| unreasonable/ʌnˈriːzənəbl/ | 妥当でない |
| heuristic/hjuːˈrɪstɪk/ | ヒューリスティック |
正しいだけでは不十分な場合もある
- 2つのアルゴリズムがどちらも正しいにもかかわらず、一方の方がはるかに使い勝手が良いことがあります。
- アルゴリズム効率は、アルゴリズムが消費するリソース(主に時間とメモリ)によって比較されます。
- 正しいが遅いアルゴリズムは、大きな入力に対して無用であることがあります。
- そのため、スケールへの対応を比較する方法が必要です。
Algorithmic efficiency compares algorithms by:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Efficiency is about time and memory as input grows.
nが増加するにつれてステップを数える
- 入力の大きさ$n$が増加する際の、アルゴリズムが必要とするステップの数を推定します。
- 線形探索は約$n$のステップを要し、二項探索は約$\log_2 n$、全ペアの比較は約$n^2$を要します。
- $n$ が大きくなると、これらの違いは巨大になります。
- ストップウォッチよりも、成長の形状の方がはるかに重要です。

アルゴリズムの実行時間が入力サイズ n とともにどのように増加するか

How running time grows with n
Slide n and compare the curves: log n stays almost flat, n rises steadily, n² explodes. This is why we compare algorithms by how they scale, not with a stopwatch.
Match each algorithm to its rough number of steps for input size n.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
These growth rates decide which algorithm scales.
Which growth is considered unreasonable as n gets large?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Exponential growth quickly becomes far too slow.
When an exact answer is too slow, a ______ finds a good-enough solution fast.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
A heuristic trades a perfect answer for speed.
妥当 vs 不適切
- 私たちは妥当な実行時間と不適切な実行時間を区別します。
- およそ、$n$ や$n^2$のような成長は妥当であり、追加のアイテムごとにステップが倍増する($2^n$のような)ものは不適切です。
- 正確な答えが非常に時間がかかる場合は、ヒューリスティックを使用します——速く見つけられた、十分許容できる解です。
- 完璧ではありませんが、完璧な解が時間内に得られない場合に有用です。
A binary search of 1,000,000 sorted items needs at most about how many steps? (2^20 ≈ a million)
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Because 2^20 is just over a million, ~20 halvings suffice.
If an algorithm is correct, it will always run fast enough on large inputs.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
False. A correct algorithm can still be too slow on large inputs; it must also finish in a reasonable time.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
Too slow to use
- This is why some correct algorithms are too slow 缓慢 to run in practice on large inputs.
- Being correct is not enough — an algorithm must also finish in a reasonable time.
A million items. A linear search of 1,000,000 sorted items may take up to 1,000,000 steps. A binary search takes at most about 20, because $2^{20}$ is just over a million. On small lists the gap barely matters; on a million sorted items, binary search can greatly reduce the number of comparisons.
アルゴリズム効率は入力のサイズ$n$が増加する際のリソースでアルゴリズムを比較します:線形$n$、バイナリ$\log_2 n$、全ペア$n^2$。$n$や$n^2$のような成長は合理的ですが、$2^n$は不合理です(ヒューリスティックを使用)。大規模な入力に対してあまりにも遅い正しいアルゴリズムでは不十分です。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。