baiyanchen8
    • 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
    • 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 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
    # 圖的抽象資料型態 ## 定義 圖由兩種基本物組成: 邊(edge)、節點(vertex) 而邊則有兩種型態(有無方向) ## 表現方式 一張圖通常是使用點集合與邊集合的方式表示(手寫),而在程式實作中通常只使用edge set(看情況) ![](https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/20240302_193111.jpg?raw=true) | graph | vertex | edge | | ----- | ------------- |:----------------------------------- | | a | 0,1,2,3 | (0,1),(0,2),(0,3),(1,2),(1,3),(2,3) | | b | 0,1,2,3,4,5,6 | (0,1),(0,2),(1,3),(1,4),(2,5),(2,6) | | c | 0,1,2 | <0,1>,<1,0>,<1,2> | *tips:* 在有向圖中,edge set 中的紀錄也會有方向(通常由前指向後<前,後>) ## Constraints (通常禁止以下的內容) 1. self edge :::spoiler 指那些由A指向A的邊,也稱 self loop EX : (A,A)、<C,C> <img src="https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/self_loop.jpg?raw=true" width="" height="288"> ::: 3. multigraph :::spoiler 擁有**多重邊**的圖即稱為 mutigraph <img src="https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/multigraph.jpg?raw=true" width="" height="288"> ::: ## 圖的各種表示法 ### 相鄰矩陣 (Adjacency Matrix) 假設共有 N 個 Vertex,使用一個N$\times$N的矩陣,並用0表示不相鄰、1表示相鄰。 :::spoiler 舉例 ![](https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/20240302_193111.jpg?raw=true) 使用$G_3$舉例 | x\y | 0 | 1 | 2 | | --- |:--- | --- | --- | | 0 | 0 | 1 | 0 | | 1 | 1 | 0 | 0 | | 2 | 0 | 1 | 0 | *tips:* 在這裡有方向性(y$\rightarrow$x) ::: #### 優點 對於尋找A,B任意兩點之間是否相鄰非常快,只需要$O(1)$ #### 缺點 空間複雜度為$O(N^2)$,且所有需要遍歷的算法都需要比較大的時間複雜度 ### 相鄰串列 (adjacency list) ![](https://ithelp.ithome.com.tw/upload/images/20200929/201298415c5bt3V6wL.png) ### 相鄰多元串列 (Adjacency Multilist) ![](https://ithelp.ithome.com.tw/upload/images/20200929/20129841c5TUcJnx8V.png) ### 索引表 (Index Table) ![](https://ithelp.ithome.com.tw/upload/images/20200929/201298414v5xQ0dfIh.png) # 圖的各種基本名詞 1. 完全圖 full graph :::spoiler 一個有*n*個邊的無向圖中,最多可能有$\frac{n(n-1)}{2}$個邊(*握手問題*),而一個擁有最多可能邊的無向圖則稱為無向圖 ### **Example** <img src="https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/fullgraph.jpg?raw=true" width="" height="288"> ::: 1. 子圖 sub-graph :::spoiler 說明 通過將原本的圖拆分,所獲得的圖即為 sub-graph ![](https://th.bing.com/th/id/R.143f05e877a98a5defd774e29b388cae?rik=z55otwB3FZ2Hbw&riu=http%3a%2f%2f3.bp.blogspot.com%2f-L7KQbEpYe6o%2fUs2MELwhrnI%2fAAAAAAAAB6M%2furqBoTOR7To%2fs1600%2fSubgraph.JPG&ehk=7mTflNxR9h9uNIZ813%2fLOfhRNT07RDwrwqi8i2lG8BE%3d&risl=&pid=ImgRaw&r=0) ::: 1. 迴圈 circle :::spoiler 說明 由一段頭尾相同的路徑組成 ::: 1. 連通 connect :::spoiler 說明 指一張圖中,若u&v之間存在至少一條路徑,即為連通 ::: 1. 連通元件 connect components :::spoiler 說明 連通元件是指在一個圖形或網路中,能夠互相連接的元素或節點集合,這些元素之間可以透過路徑相互到達。 ::: 1. 強連通圖 strongly connected components :::spoiler 說明 強連通圖是指在*有向圖*中,任意兩個節點之間都存在互相到達的路徑,也就是說,圖中的任意兩個節點都是彼此可達的。 ::: 1. 弱連通圖 weak connected components :::spoiler 說明 如果將一個*有像圖*所有有向邊替換為無向邊之後的無向圖是連通的,則稱為弱連通圖。 ::: 1. 分支度 :::spoiler 說明 1. 無向圖 所有相連邊的數量 3. 有向圖 有向圖的分支度分為入分支度 & 出分支度,就是將指向節點的邊&指出節點的邊分開計算。 ::: # 圖的基本運算 ## Deepth First Search (深度優先算法) 從字面意義上可知,是優先探索深度的算法 ```clike= int visited[num_vertex]; // 假設 non visited 為 0 , visited 為1 int edge [num_vertex][2];//假設未使用的edge內容為(-1,-1) void dfs(int now){ visited[now]=1; printf("%d ",now); int i; for (i=0;i<num_vertex;i++){ if (edge[i][0]==-1 || edge[i][1]==-1) continue; if (edge[i][0]==now && visited[edge[i][1]]==0) dfs(edge[i][1]); if (edge[i][1]==now && visited[edge[i][0]]==0) dfs(edge[i][0]); } } ``` ## Breadth First Search ```clike= int visited[num_vertex]; // 假設 non visited 為 0 , visited 為1 int edge [num_vertex][2];//假設未使用的edge內容為(-1,-1)void bfs(int now){ void bfs(int now){ addqueue(now); int tmp; while (queue){ tmp = dequeue(); if (tmp ==-1){ break; } visited[tmp] = 1; printf ("%d ", tmp); int i; for (i = 0; i < num_vertex; i++){ if (edge[i][0] == -1 || edge[i][1] == -1) continue; if (edge[i][0] == tmp && visited[edge[i][1]] == 0) addqueue(edge[i][1]); if (edge[i][1] == tmp && visited[edge[i][0]] == 0) addqueue(edge[i][0]); } } } ``` ## 連通元件 通過 dfs or bfs 尋找就可以了。 ```clike= void connected(){ bfs(); } ``` ## 生成樹 當選擇圖中一個頂點,然後使用某種算法遍歷所有頂點,把所有其中經歷的路徑記錄下來便是生成樹 ## 雙連通元件((bi-connected components)) articulation point : 將*連通圖G*中某一*節點v*刪除會出現多個(>1)連通圖,該節點極為連接點(articulation point) ![](https://github.com/baiyanchen8/hackmd-image/blob/main/%E5%9F%BA%E7%A4%8E%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B/chap6/20240317_173225.jpg?raw=true) ### low 公式 low(n)=min{dfn(n) &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;,min{low(w)\|當w為n的child on dfs tree} &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;,min{dfn(w)\|當(w,n)為back edge}} ### code 不想寫 ...... # 最小花費生成樹(Minimum spanning tree) ## greedy method # 最短路徑與遞移封閉 # 活動網路

    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