SlideShare a Scribd company logo
1 of 43
Download to read offline
アルゴリズムとデータ構造

  2012.1.13 (WEB用)
今日の内容
          第5章 基本的なアルゴリズム

• 5.1.1   最大最小値を探す
• 5.1.2   逐次検索
最大値を探すアルゴリズム
82 24 12 27 18 78 19 86 45 41 64 16 86 11 16 15 30 25 10 26


配列に入った数値の中から最大のものを探す
   手順(=アルゴリズム)考える

   手順① 仮の最大値と配列の数値を比べる。
   手順② 比べた数値のほうが大きければ、
       それを仮の最大値とする。
   手順③ 手順①&② を配列の数値に対して
       順に行う。
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”


          数値が入った配列 ar を用意(2行目)
          配列の要素数を変数 n に代入(3行目)
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”


                  仮の最大値を設定(4行目)
                  ここでは -1000 としている
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”


  総和や平均を求めたときと同様に、forループで
 配列の中の数字を一つずつ処理していく(5~9行目)
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 現在の最大値と比較
 7        max = ar[i]            # 最大値の更新
 8     end
 9   end
10   print “最大値は #{max}です”


       if 文に注目(6~8行目)
 現在の最大値より大きければその値で max を更新
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                             true
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # -1000 < 82
 7        max = ar[i]            # max = 82
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 24
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 12
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 27
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 18
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 78
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         false
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 19
 7        max = ar[i]            # 更新無し
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
                                         true!
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 82 < 86
 7        max = ar[i]            # max = 86 に更新
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
                                        max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then       # 以後、最後の数値まで
 7        max = ar[i]            # 同じ処理を繰り返す
 8     end
 9   end
10   print “最大値は #{max}です”

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
                                        max
findmax.rb
 1   # findmax.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = -1000
 5   for i in 0 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”                   # max = 86

  ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                            ⑲
 [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
                                        max
問題5-1
• findmax.rb を最大値ではなく、最小値を求め
  るように変更しなさい(ファイル名は findmin、
  変数名は min にすること)。
問題5-1 解答例
 1   # findmin.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   min = 1000
 5   for i in 0 .. n-1
 6     if min > ar[i] then
 7        min = ar[i]
 8     end
 9   end
10   print “最小値は #{min}です”


                 仮の最小値を1000のような
                大きな数字にすること(4行目)
問題5-2
• findmax.rb では,最大値の初期値として
  −1000 を与えている。これは調べ ようとしてい
  るデータの集合の値の範囲が予め分ってい
  るからである。それでは,どのよ うなデータで
  あればこのプログラムは誤動作するか。配列
  ar の数値を書き換えて,プロ グラムが間違っ
  た結果を出すようにしなさい
問題5-2
• findmax.rb では,最大値の初期値として
  −1000 を与えている。これは調べ ようとしてい
  るデータの集合の値の範囲が予め分ってい
  るからである。それでは,どのよ うなデータで
  あればこのプログラムは誤動作するか。配列
  ar の数値を書き換えて,プロ グラムが間違っ
  た結果を出すようにしなさい


     -1000より小さい数値だけ入った配列
問題5-3
• 5-2の問題点を踏まえて、どんなデータの集
  合が与えられても最大値が求められるように
  するには、ソースをどう書き換えたらよいか
  (ファイル名は findmax2.rb)。


         ヒント
配列内の数値のどれかを仮の最大値に設定する
問題5-3 解答例
 1   # findmax2.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = ar[0]
 5   for i in 1 .. n-1
 6     if max < ar[i] then
 7        max = ar[i]
 8     end
 9   end
10   print “最大値は #{max}です”


 配列の一番最初の数値を仮の最大に設定(4行目)
 ループは0番目からではなく1番目から開始(5行目)
問題5-4
• findmax2.rb 書き換えて、

   “最大値は 〜 で、〜 番目にあります。”

 という形で表示するようにしなさい。
問題5-4 解答例
 1   # findmax3.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   max = ar[0]
 5   imax = 0
 6   for i in 1 .. n-1
 7     if max < ar[i] then
 8        max = ar[i]
 9        imax = i
10     end
11   end
12   print “最大値は #{max} で #{imax} 番目にあります。”
逐次検索
配列の中の数値を一つずつ足して総和を求めたり、比較
して最大値または最小値を求めたりと、これまで for ルー
プで配列の中の値を逐次的に処理してきた。


⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩                         ⑲
[82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]

           ひとつずつ くまなく 順番にチェック!
         = 逐次探索 (sequential search)
         = 線形探索 (linear search)

この方法で、任意の値(探索キー)が配列内にあるかどうか
を判定するプログラムを書いてみましょう
任意の値を探すアルゴリズム
82 24 12 27 18 78 19 86 45 41 64 16 86 11 16 15 30 25 10 26


配列に入った数値の中から探索キーが存在するか
 どうかを判定するプログラムの手順を考える

   手順① 配列の要素を一つずつ取り出す
   手順② その値が探索キーと一致したら、
       探索を終了し「見つかった」と出力
   手順③ 最後まで見つからなかったら。
       「見つからなかった」と出力
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i ・・・・ # 探索キーをコマンドライン引数で
 5   found = false                  受け取り変数 key に代入
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false ・・・・ # 見つかったかどうかを判定するための
 6   for i in 0 .. n-1         フラグ変数を用意。最初はfalse
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1   ・・・・・・ # 6行めから12行まで for ループ
 7     if ar[i] == key then         配列の値をひとつずつ取り出して
 8        found = true              逐次的に処理
 9        ifound = i
10        break
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then ・・・・ # if 文で 配列の値 ar[i] と key が
 8        found = true               一致するかどうかを判別
 9        ifound = i
10        break
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true ・・・・ # もし一致すれば found を true に変更
 9        ifound = I    ・・・・・・ # その値の添字番号を ifound に記憶
10        break      ・・・・・・・・・ # break でループを終了し13行目に移る
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true             # 一致する値が見つかない場合は
 9        ifound = I                 if 文は一度も実行されないので
10        break                      found は false のままループが終了
11     end
12   end
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break
11     end                # 値が見つかっていればfound はtrueなので
12   end                    「~は~番目にありました」と出力(14行目)
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break
11     end               # そうでなければ else 文に入って
12   end                   「~は見つかりませんでした」と出力(16行目)
13   if found then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        break           # 13行目は 以下のように記述しても良いが
11     end                  変数がそのものが 論理値の場合は
12   end                    “== true”を省略出来る
13   if found == true then
14     puts “#{key} は #{ifound} 番目にありました。”
15   else
16     puts “#{key} は見つかりませんでした。”
17   end
seqsearch.rb
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1         この例の変数 found ように
 7     if ar[i] == key then 「見つかった」という状態(= true) と
 8        found = true         「見つからなかった」という状態(= false)
 9        ifound = i           どちらかを記憶させるために使われる場合
10        break                これをフラグ(flag) 変数という
11     end
12   end
13   if found then ・・・・ # 見つかった場合
14     puts “#{key} は #{ifound} 番目にありました。”
15   else ・・・・ # 見つからなかった場合
16     puts “#{key} は見つかりませんでした。
17   end
問題5-X
• seqsearch.rb では値が見つかると break で即
  座にループを終了している。しかし、配列の
  中には 86 のように複数個存在しているもの
  もあり、この場合一番最初の 86 について添
  字番号が出力されるが、2つ目以降は無視さ
  れる。
• seqseach.rbを改良し、値が複数存在する場
  合についても、全て添字番号が出力されるよ
  うにしなさい。
問題5-X 解答例
 1   # seqsearch.rb
 2   ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26]
 3   n = ar.size
 4   key = ARGV[0].to_i
 5   found = false
 6   for i in 0 .. n-1
 7     if ar[i] == key then
 8        found = true
 9        ifound = i
10        puts “#{key} は #{ifound} 番目にありました。”
11     end
12   end
13   if found != true
14     puts “#{key} は見つかりませんでした。”
15   end
今日のまとめ
• 最大値と最小値を探すアルゴリズム
        → findmax.rb / findmin.rb

• 探索キーが存在するかを判別するアルゴリズム
        → seqseach.rb

どちらも配列の要素を逐次的に処理する方法で実装
来週は
• 1月20日

• 第5章残り(素数判定のアルゴリズム)

• プログラミング道場の補足

• 授業アンケート

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

2012年1月13日

  • 2. 今日の内容 第5章 基本的なアルゴリズム • 5.1.1 最大最小値を探す • 5.1.2 逐次検索
  • 3. 最大値を探すアルゴリズム 82 24 12 27 18 78 19 86 45 41 64 16 86 11 16 15 30 25 10 26 配列に入った数値の中から最大のものを探す 手順(=アルゴリズム)考える 手順① 仮の最大値と配列の数値を比べる。 手順② 比べた数値のほうが大きければ、 それを仮の最大値とする。 手順③ 手順①&② を配列の数値に対して 順に行う。
  • 4. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です”
  • 5. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です” 数値が入った配列 ar を用意(2行目) 配列の要素数を変数 n に代入(3行目)
  • 6. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です” 仮の最大値を設定(4行目) ここでは -1000 としている
  • 7. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です” 総和や平均を求めたときと同様に、forループで 配列の中の数字を一つずつ処理していく(5~9行目)
  • 8. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then # 現在の最大値と比較 7 max = ar[i] # 最大値の更新 8 end 9 end 10 print “最大値は #{max}です” if 文に注目(6~8行目) 現在の最大値より大きければその値で max を更新
  • 9. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 true 5 for i in 0 .. n-1 6 if max < ar[i] then # -1000 < 82 7 max = ar[i] # max = 82 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 10. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 24 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 11. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 12 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 12. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 27 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 13. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 18 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 14. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 78 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 15. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 false 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 19 7 max = ar[i] # 更新無し 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 16. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 true! 5 for i in 0 .. n-1 6 if max < ar[i] then # 82 < 86 7 max = ar[i] # max = 86 に更新 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 17. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then # 以後、最後の数値まで 7 max = ar[i] # 同じ処理を繰り返す 8 end 9 end 10 print “最大値は #{max}です” ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 18. findmax.rb 1 # findmax.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = -1000 5 for i in 0 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です” # max = 86 ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] max
  • 19. 問題5-1 • findmax.rb を最大値ではなく、最小値を求め るように変更しなさい(ファイル名は findmin、 変数名は min にすること)。
  • 20. 問題5-1 解答例 1 # findmin.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 min = 1000 5 for i in 0 .. n-1 6 if min > ar[i] then 7 min = ar[i] 8 end 9 end 10 print “最小値は #{min}です” 仮の最小値を1000のような 大きな数字にすること(4行目)
  • 21. 問題5-2 • findmax.rb では,最大値の初期値として −1000 を与えている。これは調べ ようとしてい るデータの集合の値の範囲が予め分ってい るからである。それでは,どのよ うなデータで あればこのプログラムは誤動作するか。配列 ar の数値を書き換えて,プロ グラムが間違っ た結果を出すようにしなさい
  • 22. 問題5-2 • findmax.rb では,最大値の初期値として −1000 を与えている。これは調べ ようとしてい るデータの集合の値の範囲が予め分ってい るからである。それでは,どのよ うなデータで あればこのプログラムは誤動作するか。配列 ar の数値を書き換えて,プロ グラムが間違っ た結果を出すようにしなさい -1000より小さい数値だけ入った配列
  • 23. 問題5-3 • 5-2の問題点を踏まえて、どんなデータの集 合が与えられても最大値が求められるように するには、ソースをどう書き換えたらよいか (ファイル名は findmax2.rb)。 ヒント 配列内の数値のどれかを仮の最大値に設定する
  • 24. 問題5-3 解答例 1 # findmax2.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = ar[0] 5 for i in 1 .. n-1 6 if max < ar[i] then 7 max = ar[i] 8 end 9 end 10 print “最大値は #{max}です” 配列の一番最初の数値を仮の最大に設定(4行目) ループは0番目からではなく1番目から開始(5行目)
  • 25. 問題5-4 • findmax2.rb 書き換えて、 “最大値は 〜 で、〜 番目にあります。” という形で表示するようにしなさい。
  • 26. 問題5-4 解答例 1 # findmax3.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 max = ar[0] 5 imax = 0 6 for i in 1 .. n-1 7 if max < ar[i] then 8 max = ar[i] 9 imax = i 10 end 11 end 12 print “最大値は #{max} で #{imax} 番目にあります。”
  • 27. 逐次検索 配列の中の数値を一つずつ足して総和を求めたり、比較 して最大値または最小値を求めたりと、これまで for ルー プで配列の中の値を逐次的に処理してきた。 ⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑲ [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] ひとつずつ くまなく 順番にチェック! = 逐次探索 (sequential search) = 線形探索 (linear search) この方法で、任意の値(探索キー)が配列内にあるかどうか を判定するプログラムを書いてみましょう
  • 28. 任意の値を探すアルゴリズム 82 24 12 27 18 78 19 86 45 41 64 16 86 11 16 15 30 25 10 26 配列に入った数値の中から探索キーが存在するか どうかを判定するプログラムの手順を考える 手順① 配列の要素を一つずつ取り出す 手順② その値が探索キーと一致したら、 探索を終了し「見つかった」と出力 手順③ 最後まで見つからなかったら。 「見つからなかった」と出力
  • 29. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 30. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i ・・・・ # 探索キーをコマンドライン引数で 5 found = false 受け取り変数 key に代入 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 31. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false ・・・・ # 見つかったかどうかを判定するための 6 for i in 0 .. n-1 フラグ変数を用意。最初はfalse 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 32. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 ・・・・・・ # 6行めから12行まで for ループ 7 if ar[i] == key then 配列の値をひとつずつ取り出して 8 found = true 逐次的に処理 9 ifound = i 10 break 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 33. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then ・・・・ # if 文で 配列の値 ar[i] と key が 8 found = true 一致するかどうかを判別 9 ifound = i 10 break 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 34. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true ・・・・ # もし一致すれば found を true に変更 9 ifound = I ・・・・・・ # その値の添字番号を ifound に記憶 10 break ・・・・・・・・・ # break でループを終了し13行目に移る 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 35. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true # 一致する値が見つかない場合は 9 ifound = I if 文は一度も実行されないので 10 break found は false のままループが終了 11 end 12 end 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 36. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break 11 end # 値が見つかっていればfound はtrueなので 12 end 「~は~番目にありました」と出力(14行目) 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 37. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break 11 end # そうでなければ else 文に入って 12 end 「~は見つかりませんでした」と出力(16行目) 13 if found then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 38. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 break # 13行目は 以下のように記述しても良いが 11 end 変数がそのものが 論理値の場合は 12 end “== true”を省略出来る 13 if found == true then 14 puts “#{key} は #{ifound} 番目にありました。” 15 else 16 puts “#{key} は見つかりませんでした。” 17 end
  • 39. seqsearch.rb 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 この例の変数 found ように 7 if ar[i] == key then 「見つかった」という状態(= true) と 8 found = true 「見つからなかった」という状態(= false) 9 ifound = i どちらかを記憶させるために使われる場合 10 break これをフラグ(flag) 変数という 11 end 12 end 13 if found then ・・・・ # 見つかった場合 14 puts “#{key} は #{ifound} 番目にありました。” 15 else ・・・・ # 見つからなかった場合 16 puts “#{key} は見つかりませんでした。 17 end
  • 40. 問題5-X • seqsearch.rb では値が見つかると break で即 座にループを終了している。しかし、配列の 中には 86 のように複数個存在しているもの もあり、この場合一番最初の 86 について添 字番号が出力されるが、2つ目以降は無視さ れる。 • seqseach.rbを改良し、値が複数存在する場 合についても、全て添字番号が出力されるよ うにしなさい。
  • 41. 問題5-X 解答例 1 # seqsearch.rb 2 ar = [82, 24, 12, 27, 18, 78, 19, 86, 45, 41, 64, ..., 26] 3 n = ar.size 4 key = ARGV[0].to_i 5 found = false 6 for i in 0 .. n-1 7 if ar[i] == key then 8 found = true 9 ifound = i 10 puts “#{key} は #{ifound} 番目にありました。” 11 end 12 end 13 if found != true 14 puts “#{key} は見つかりませんでした。” 15 end
  • 42. 今日のまとめ • 最大値と最小値を探すアルゴリズム → findmax.rb / findmin.rb • 探索キーが存在するかを判別するアルゴリズム → seqseach.rb どちらも配列の要素を逐次的に処理する方法で実装
  • 43. 来週は • 1月20日 • 第5章残り(素数判定のアルゴリズム) • プログラミング道場の補足 • 授業アンケート