Hsu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 問題解決力を鍛える!アルゴリズムとデータ構造 https://github.com/drken1215/book_algorithm_solution ## 第3章 - 任意参加 - ファシリテーター: 許 ### 話す・書く順番決めルーレット in Ruby ```ruby ['hsu', 'chen', 'teruya', 'kanazawa', 'okura', 'tsujita'].shuffle.each { |v| puts ">[name=#{v}]\n\n" } ``` in JavaScript ```javascript const l = ['hsu', 'chen', 'teruya', 'kanazawa', 'okura', 'tsujita'] l[Math.floor(Math.random()*l.length)] ``` ### ファシリテーター決め方 - `%w(hsu chen teruya kanazawa okura kanno)`の順番でやっていく ### 参加者がやること - 事前に決められた章を読む - 学んだことやわからなかったことを書き込む(任意) 当日 - 最初に感想や質問を書く時間を設ける(10分) - 時間枠 60分 - 延長枠 30分 ### 勉強会時にやること 各自学びや気付き、疑問を発表していく ファシリテーターがよしなに議論を進める 終了前に勉強会を振り返る?(KPTなどで)← 60分のときに仮締め ## 各自が書き込む場所 > [name=Chen] #### 3.1 全探索 (1):線形探索法ーO(N) めっちゃめっちゃ使っているやつと思います 配列の値を探す、判断する、計算するなどの定番。 #### 3.2 全探索 (2):ペアの全探索ーO(N^2) 二重forループのアルゴリズム。 お二つの配列を比較し、または計算する時によく使っている。 #### 3.3 全探索 (3):組合せの全探索 (*)ーO(N2^N) > N 個の整数からなる集合の部分集合は 2^N 通りあります。…それらを全探索する方法です。 N の集合 {a0, a1, ..., aN-1} の部分集合をすべて走査できる方法で、 初めて知りました。 が、二進法表現とビット演算は少し理解しにくい...:thinking_face: > [name=teruya] > 探索中にvが見つかったら探索を打ち切ってbreakする ... しかしこの工夫を施しても、計算量のオーダーという意味でのアルゴリズムの良さは変わりません(p.74) Array#find > code3.6 部分和問題に対するビットを用いる全探索解法 ```=ruby n, w = gets.split.map(&:to_i) nums = gets.split.map(&:to_i) exist = false # n = 3の時、 bit は 0(000), 1(001), 2(010) ... 7(111) までの 8 通り (2 ** n).times do |bit| sum = 0 # n = 3の時はbitを3つ調べる n.times do |i| # bit が 6(110) の時、bit[0]は0、bit[1]は1、bit[2]は1 sum += nums[i] if bit[i] == 1 end exist = true if sum == w end puts exist ``` ```=ruby n, w = gets.split.map(&:to_i) nums = gets.split.map(&:to_i) exist = false (1..n).each do |i| # [1, 3, 5].combination(2) は [1, 3], [1, 5], [3, 5]がselected_numsに渡る nums.combination(i) do |selected_nums| exist = true if selected_nums.sum == w end end puts exist ``` > 3.5 N個の正の整数... https://atcoder.jp/contests/abc051/submissions/6941239 O(N^3) を O(N^2) に落とす問題 (例えば0〜100の中から3回選んで合計250を作りたいとして、 1つ目100,2つ目200の時に、3つ目は全探索しなくても0を選べば200、100を選べば300なんだから その間の250も作れるはずじゃない?みたいな感じ) > [name=hsu] 3.3 find_id ```javascript const LinerSearch = (arr, x) => { for (i = 0; i < arr.length; i++) { if (arr[i] === x) return i; } return -1; }; ``` best : O(1)? worse: O(N) 3.3.2 find_minValue ```javascript const FindMinValueByLinerSearch = (arr) => { let minValue = arr[0] for (i = 1; i < arr.length; i++) { if (arr[i] < minValue) minValue = arr[i] } return minValue }; ``` best : O(1)? worse: O(N) average: O(N / 2) でも、1/2は誤差なので取り除く、なので結局O(N) 例えばN = 1,000,000 の時, N * 2 = 2,000,000 N / 2 = 500,000 N * N = 1,000,000,000,000 worst: O(N) 3.6 c++のcodeわからない... ```c++ int N, W; cin >> N >> W; vector<int> a(N); for (int i = 0; i < N; ++i) cin >> a[i]; ここはなんだろう? ``` '>>' 入力、アサイン '<<' 出力 > [name=okura] ### 3.1 全探索を学ぶ意義 一番基本だから、ということですね。 ### 3.2 全探索(1):線形探索法 いつも最初に思いついて、だいたいうまくいかない(時間がかかりすぎる)やつ。 ### 3.3 線形探索法の応用 探索プログラムが状態を持っている、ということで、その「状態」に何を格納しておくかを変えることで目的に応じた探索が可能。 ### 3.4 全探索(2):ペアの全探索 > なお,実はこの問題は二分探索法を用いることで,O(NlogN)で解くこともできます それはすごい。 ### 3.5 全探索(3):組み合わせの全探索 探索の対象全てをビットとして表現するというのはなるほどという感じ。最初にあり得る組み合わせを全部出しておくことで解法を単純化できるのだと思う。 ### 章末問題 解けてない… ## 振り返り > [name=hsu] 普段linerSearch書いてますが、実際あまり意識してなかった。。。二重loop使わないように意識していきます。 > [name=teruya] 取り得る値がbooleanの2値の時に、bitを使って管理したら簡単やん!って思いついた人すごい。 (けどすごすぎて日常ではあまり馴染みがない) とりあえず配列がunsortedの時はO(NlogN)でソートしてから考えるみたいなのはよくあります😂 > [name=chen] ビット演算はマジで難しい...アルゴリズム力不足:cry: > [name=okura] 「これ、対象がソート済みだったらなあ」→「ソートすればいいのでは???」みたいな。 ## 終了後ファシリテーターがやること - 次回のファシリテーターを決める - Chenさん - 読む範囲を決める - 第4.3章まで

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully