ハーバード大学のCS50でコンピュータサイエンス入門

ハーバード大学のCS50でコンピュータサイエンス入門

January 30, 2021

ハーバード大学が無償で公開してくれている「CS50’s Introduction to Computer Science」という動画講義に取り組みましたので、そちらの記録です。以降、本講座のことを「CS50x」と略します。(講義のページに「This is CS50x」と記載があるので、この略し方でたぶん合ってるはず。)

なお、昨年末に「CS50’s Web Programming with Python and JavaScript(略して CS50w)」という WEB アプリ開発向けの公開講座を視聴済みです。

本来は CS50x を受講してから、(WEB アプリ開発についてさらに学ぶ場合は)CS50w を受講するという流れのようなのですが、私はそれを知らずに逆走した形となっています。

CS50x(2021 年バージョン)は全 11 週から成りますが、その内容は大きく3パートに分けることができます。(なお、私が勝手にそう感じているだけです。)

CS50’s Introduction to Computer Science | 講義全 11 回

https://www.edx.org/course/cs50s-introduction-to-computer-science

  • WEEK 0 : Scratch
  • WEEK 1 : C
  • WEEK 2 : Arrays
  • WEEK 3 : Algorithms
  • WEEK 4 : Memory
  • WEEK 5 : Data Structures
  • WEEK 6 : Python
  • WEEK 7 : SQL
  • WEEK 8 : HTML, CSS, JavaScript
  • WEEK 9 : Flask
  • WEEK 10 : Ethics

1つ目のパートが WEEK 0〜5「Scratch/C 言語を用いたコンピュータサイエンスの学習」、2つ目のパートが WEEK 6〜9「WEB アプリ開発の学習」、3つ目のパートが、WEEK10「倫理・哲学」です。

私の場合、WEB アプリ開発の部分を再度学習する必要性は感じなかったため、それ以外のパートを視聴しました。

以下、講義内容と所感をまとめます。

講義の内容 #

  • WEEK 0 : Scratch
    • 動画時間:1 時間 41 分
    • 内容
      • コンピュータがどのように情報を表現するか(2進数)
      • コンピュータの処理の流れ(input/algorithm/output)
      • Scratch
    • 課題
  • WEEK 1 : C
    • 動画時間:2 時間 16 分
    • 内容
      • C 言語の基本(変数、演算子、if 文、while 文、for 文、関数)
      • コマンドライン
    • 課題
      • スーパーマリオブラザーズに出てくる階段を表示するプログラム1
      • スーパーマリオブラザーズに出てくる階段を表示するプログラム2
      • お釣り計算プログラム
      • クレジットカード番号の妥当性検証プログラム
  • WEEK 2 : Arrays
    • 動画時間:2 時間 24 分
    • 内容
      • プログラムをビルドするときの内部処理の流れ
        1. preprocessing:プリプロセッシング … include している他のソースファイルを読み込んだりする処理
        2. compiling:コンパイリング … ソースコードをアセンブリに変換する
        3. assembling:アセンブリング … アセンブリを機械語(0/1)ファイルに変換する
        4. linking:リンキング … (include している参照先含めた)それぞれの機械語ファイルを結合して1つの機械語ファイルにまとめる
      • デバッグ
        • “debugger is your friend.”
      • メモリ
      • 配列
    • 課題
      • リーダビリティ(読みやすさ指標)算出プログラム
      • シーザー暗号プログラム
  • WEEK 3 : Algorithms
    • 動画時間:2 時間 25 分
    • 内容
      • 線形探索(リニアサーチ)
      • 二分探索(バイナリサーチ)
      • バブルソート
      • 選択ソート
      • マージソート
    • 課題
      • Runoff voting system(優先順位付投票制)プログラム
      • Tideman voting system プログラム
  • WEEK 4 : Memory
    • 動画時間:2 時間 41 分
    • 内容
      • ポインタ(& と *)
      • メモリの確保と開放(malloc と free)
      • スタックとヒープ
    • 課題
      • 画像処理:グレースケール
      • 画像処理:セピア
      • 画像処理:左右反転
      • 画像処理:ぼかし
      • 画像処理:エッジ
      • 画像の復元
  • WEEK 5 : Data Structures
    • 動画時間:2 時間 26 分
    • 内容
      • リンクリスト(連結リスト)
      • ハッシュテーブル
      • トライ木
      • スタック・キュー
    • 課題
      • スペルチェッカー
  • WEEK 10 : Ethics
    • 動画時間:1 時間 17 分
    • 内容
      • プログラミングについて振り返り
      • サービスを開発する時に考慮すべき倫理の話
      • これからプログラミングを続ける中で意識すべきこと
        • こんなツールを使うと良いよ
        • こんなウェブサイトを見ると良いよ
      • これまでの総復習クイズ

講義の所感 #

  • WEEK 0 : Scratch
    • スクラッチの存在は知っていたものの、今回初めて触りました。プログラミングの入門として非常に良いと感じました。
  • WEEK 1 : C
    • C 言語の入門です。はじめての C 言語でしたので新鮮でした。
  • WEEK 2 : Arrays
    • プログラムがビルドされる流れを丁寧に説明してくれていて理解が深まりました。「printf is your friend.」「debugger is your friend.」というメッセージが印象的でした笑
  • WEEK 3 : Algorithms
    • ソートだったりサーチだったり、アルゴリズム(アルゴリズム - Wikipedia)の話です。色々な道具を使ってわかりやすく説明してくれます。課題には苦労しましたが楽しかった。
  • WEEK 4 : Memory
    • プログラムが実行される時にメモリがどう使われるのかという話です。非常に勉強になります。課題には苦労しましたが楽しかった(その2)。
  • WEEK 5 : Data Structures
    • データ構造(データ構造 - Wikipedia)の話です。難しいけれど面白い。課題を1人でクリアすることができず、有志が解説してくれている Youtube だったり、Medium のブログだったりを参考にして完成させました。正直、1人の力では作り切ることが全然できていないため、まだまだ理解が足りないのだろうなと感じています…。
  • WEEK 10 : Ethics
    • 民主的なプラットフォームを作る際の考慮事項の話は非常に勉強になりました。その内容は後述の補足にて記載したいと思います。総復習クイズはとても面白い。個人的には以下の問題が好きでした。
      • What is a cookie?
        • data used to identify your computer to websites
        • a delicious snack
        • both of the above
        • none of the above
      • 正解は「both of the above」でした笑

補足1:Speller の Big Board の廃止 #

WEEK 5 の課題は「Speller」というものです。私が取り組んだのは 2021 年版の CS50x でしたが、課題自体は 2020 年版でも同様です。2020 年版までは、各々が作った Speller の処理性能を競わせるような仕組みがあったのですが、2021 年版ではその仕組み(Big Board)が廃止されたようです。

CS50x(2021)の Speller 課題のページには以下の記述がありました。

Big Board

If you’ve worked on this problem in the past, you know that we formerly had a “Big Board” against which students could compare their benchmark times for their spell-checker against other students. After some consideration, afraid we’ve decided to retire the Big Board for 2021!

https://cs50.harvard.edu/x/2021/psets/5/speller/#big-board

その理由が気になったので調べたところ、Reddit に以下のようなコメントがありました。

Here’s what Mr. Lloyd (Doug) wrote in the discord:

At the end of the day, the Big Board had become WAY too gamified and people kept submitting solutions that totally contravened the spirit of the competition, which was increasingly frustrating for “those less comfortable” as well, and that was becoming an issue. That, plus far too many complaints and time spent removing illegal submissions, and frankly not enough upside any longer, and that’s the decision we made. I know folks, like many of you in this channel, enjoyed the challenge, and I’m sorry that you are the ones who probably lose out the most on the educational opportunity of it. I encourage you to take what you know and develop an off-site solution!

https://www.reddit.com/r/cs50/comments/l3ncv9/no_big_board_in_cs50_anymore/

ちなみに、Doug Lloyd さん(https://douglloyd.com/)は講義を指揮している方みたいですね。

About

I am, since 2020, CS50’s Head of Online Education Initiatives. In this role I coordinate all seven of CS50’s courses on edX as well as serving as the Head Teaching Fellow for all of our courses at Harvard University’s Division of Continuing Education (DCE).

https://douglloyd.com/

補足2:民主主義が正しく機能したプラットフォームの条件 #

「WEEK 10 : Ethics」で語られた内容です。良い内容だったのでここに記載します。

Well-functioning democracy platform

そのプラットフォーム(ソーシャルメディア)で民主主義が正しく機能しているかを測定するためには、以下の5点が満たされていることを確認する。

  1. Rights
    • As citizens of a democracy, we have rights to basic liberties, such as liberties of expression and association. The right to expressive liberty is important not only for the freedom of the individual, so that he or she is not censored, but also for democracy itself. It enables citizens to bring their ideas into conversation with one another, and to criticize and hold accountable those who exercise power.
  2. The opportunity for Expression
    • Not only should we be free of censorship but we should have fair opportunity to participate in public discussion. It shouldn’t be the case that because someone is wealthier or more powerful that they should have more opportunity to participate.
  3. Access
    • Each person should have good and equal access to quality and reliable information on public matters. That is, IF we make the effort, we should be able to acquire this information. Effective participation in decision makeing on public matters requires being informed.
  4. Diversity
    • Each person should have good and equal chances to hear a wide range of views. We need access to competing views in order to have a more infromed and reasoned position.
  5. Communicative Power
    • Citizens should have good and equal chances to explore interests and ideas in association with others, and through these associations, to develop new concerns that challenge the mainstream view.

感想 #

コンピュータサイエンス面白いですね。ハーバード大学の説明の仕方も非常に上手で、難しい内容でも視覚的に理解でき(るような気がし)ます。

また今回、C 言語に初めて触れました。C 言語はある意味極めてシンプルな言語なのですが、その分、自分で 0 から 100 まで実装しなければならず、日頃使っている他の言語のありがたみを知りました。C 言語を理解すると、いままで書いていたコードが裏では実際にはどのように動いていたのかの理解が進む(?)のかなと感じます。C 言語を使って自分で実際に何かアプリを作る機会は今のところ無いとは思いますが、C 言語自体の理解はこれからも進めていきたいです。