JJJJJJ
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    6
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # MIT midterm/Final ## T/F ![](https://i.imgur.com/zTCO627.png) > 四維用人腦不好想像,先想二維:$T(n) = T(n/2) + O(n), T(n) = O(n)$ ![](https://i.imgur.com/8bH7L0r.png) > WTF ![](https://i.imgur.com/9MfhwBo.png) > WTF ![](https://i.imgur.com/OomGyMu.png) > WTF ![](https://i.imgur.com/k78UwYj.png) > 什麼的rotation? ![](https://i.imgur.com/zmrRvNR.png) > ![](https://i.imgur.com/khdSQsY.png) ![](https://i.imgur.com/v4wZr97.png) > substring是連在一起的,subsequence是可以分開的 ![](https://i.imgur.com/guAxJp7.png) > But 如果是問 insert "rotation"的cost,是 O(1) ![](https://i.imgur.com/7JOLh36.png) ![](https://i.imgur.com/Bl4C9Dd.png) > ![](https://i.imgur.com/5pMmPP7.png) ![](https://i.imgur.com/i89IEDh.png) ![](https://i.imgur.com/LEP7WjA.png) ![](https://i.imgur.com/EPYCqax.png) > 上面例子中weight都等於 1,所以在證明greedy choice property時,用greedy choice取代原本的optimal choice後,至少一樣好,但是在weighted interval當中,greedy choice的weight可能比optimal choice的weight還低,所以greedy choice正確性就不成立了 > ![](https://i.imgur.com/QiBvgOE.png) ![](https://i.imgur.com/hvKHJxe.png) > ![](https://i.imgur.com/vXLLp9A.png) ![](https://i.imgur.com/Al5tNVA.png) > 在Worst case $O(nlogn)$的情況下,$T(n) = 2T(n/2) + n$ (不一定要完美split成兩半,只要分成any constant fraction都可以是$O(nlogn)$) > 只需要$O(logn)$去存unsort array的start address ![](https://i.imgur.com/kXBsnED.png) > randomized quicksort 是對**任何**input都有 **expected** $O(nlgn)$ > 當然可以說**某些**input在**某些時候**會有$O(n^2)$的表現 > 但是不可能 always runs in $O(n^2)$ ![](https://i.imgur.com/4um7EpO.png) ![](https://i.imgur.com/nb4Swcj.png) ![](https://i.imgur.com/am8AUNx.png) ![](https://i.imgur.com/aanMfCD.png) > lightest edge 一定在 MST裡面是正確的,heaviset edge一定不在MST中嗎?不一定,例如heaviset edge為bridge ![](https://i.imgur.com/WqHPcLB.png) ![](https://i.imgur.com/T08eTyA.png) > 因為edge (u,v)只加了vertex 的weight各一半,所以最後還要再加上 $1/2 (w(u) + w(v))$ 才會是正確的shortest path weight ![](https://i.imgur.com/kzRz9Md.png) ![](https://i.imgur.com/dCX6mYM.png) ![](https://i.imgur.com/kt76rFD.png) ![](https://i.imgur.com/eZAA132.png) ![](https://i.imgur.com/CMZAYhI.png) ![](https://i.imgur.com/OFSt0IX.png) ![](https://i.imgur.com/NOpldzL.png) ![](https://i.imgur.com/XXK9qIC.png) > $T(n) = T(n/9) + T(8n/9) + \theta (n)$ > $T(n) = \theta (nlgn)$ ![](https://i.imgur.com/Qrz9yyZ.png) > True: > 令 potential function = $\sum_{i=0}^{n} 2w_i$, $w_i$為每個node在heap中的depth > so root 的$w_i = 0$,root的兩個child $w_i = 1$ > > For insert: > $\hat Ci = Ci + \Phi(Hi) - \Phi(H\text{i-1}) = Ci + 2h$, $h$為 heap depth = $O(logn)$ > $\hat Ci = O(logn) + O(logn) = O(logn)$ > For extract-min: > $\hat Ci = Ci + \Phi(Hi) - \Phi(H\text{i-1}) = Ci + (-2h)$ > $\hat Ci = O(logn) + (-O(logn)) = O(1)$ ![](https://i.imgur.com/yFplywM.png) ![](https://i.imgur.com/8RK7ukT.png) ![](https://i.imgur.com/m8ourTE.png) ![](https://i.imgur.com/SU8hASb.png) > DP 的 sub problem tree 不需要是 rooted tree,只需要是 DAG即可 ![](https://i.imgur.com/8hPhT2p.png) > 原本的min cut每一條edge都 + 1,可能不再是 min cut ![](https://i.imgur.com/z99r3WN.png) ![](https://i.imgur.com/wAK60KB.png) ![](https://i.imgur.com/RNpmf8Q.png) > 3SAT is NP-Complete, 所以若 P = NP,有polynomial time algorithm > 但是如果是 NP-hard but not in NP, 例如 halting problem,則就算 P = NP,還是沒有polynomial time algorithm > ![](https://i.imgur.com/aOyN701.png) ![](https://i.imgur.com/V4wjI3Q.png) > not "always" > 就像 random quicksort runs in expected $O(nlgn)$ for **all input**, 但是還是會有**某些**input在**某次**執行時的**worst case**是 $O(n^2)$ ![](https://i.imgur.com/02oRQMi.png) > Approximation factor 和 reduction沒有絕對關係 ![](https://i.imgur.com/baiwObv.png) ![](https://i.imgur.com/B7GQwcW.png) > edge weight unique, MST is unique, but second lowest ST is not. > 找second lowest ST就是移除 MST中最大edge weight,加入尚未在MST中,不會形成cycle且weight最小的edge > 反例:![](https://i.imgur.com/WMxogQX.jpg) ![](https://i.imgur.com/nlogNbs.png) > at most k edges是 Bellman-ford的觀念 > Floyd-Warshall的核心就是DP on k, where k is intermediate vertex from 1 to n ![](https://i.imgur.com/ZYTTdet.png) > 同樣道理,Accounting method的 bank 存款也不能為負 ![](https://i.imgur.com/HlAc7yn.png) ![](https://i.imgur.com/7a7z8eS.png) ![](https://i.imgur.com/UVGa64L.png) ![](https://i.imgur.com/Ix3IuC0.png) ![](https://i.imgur.com/okWPYs0.png) > Master theorem case 3: ![](https://i.imgur.com/C7beWel.png) ![](https://i.imgur.com/bXexDEN.png) > $m*1/m^{3}$ ![](https://i.imgur.com/iolpBXF.png) > 這是在說對於所有sort 最多就是$nlgn$個比較,但是像是insertion sort就有可能 $n^2$ (little o 是對於所有 n 都要成立) 等於說sorting得上限被壓到nlgn了(問題是it's not the case) -- ![](https://i.imgur.com/CqIecUO.png) ![](https://i.imgur.com/DDYrcIZ.png) > WLOG,先排好 ACD,接著用兩次comparison找出E的位置,E排在哪裡都沒差,因為先前假設A > B,所以B也一定只會需要和三個人比較,也就是兩次comparison ![](https://i.imgur.com/EuLmIix.png) ![](https://i.imgur.com/6H5uiN6.png) > 第一點:decision tree必須要是balanced(對任何input,建構出來的decision tree),才可以說因為 $2^h > n!$,所以必定可以sort好 第二點:$lg(n!)$ 和 $nlgn$ 只是 theta bound的關係,數字大小沒有絕對關係 ![](https://i.imgur.com/L2CMvtS.png) --- ![](https://i.imgur.com/smnnYGg.png) ![](https://i.imgur.com/WsQHg0X.png) > $source ->t ->... ->u->v$ $d[v] = d[u] + w(u, v)$, in which $w(u,v) > 0$ 我們可以從後面一個一個往前推,u在到v的s-t path中,再往前推,最後推到t, t是s到v的shortest path中最靠近s 的node,因此可以證明t也在shortest path中,因為edge weight 只有在從s出去的時候才是 < 0,但s為起點,一定在shortest path中(因為是求s到v的shortest path,所以不影響正確性),所以t也必定在shortest path中。 > 要注意:Dijkstra的**正確性**是建立在**沒有 negative weight edge**之上,而不是沒有negative weight cycle。 ![](https://i.imgur.com/q3fbHcx.png) ![](https://i.imgur.com/0HDPQ3X.png) ![](https://i.imgur.com/MVbFVQR.png) ![](https://i.imgur.com/HF9seWL.png) ![](https://i.imgur.com/oo2eE3a.png) ![](https://i.imgur.com/cbUEtFd.png) > $n(n+1) / 2*n = (n+1) / 2$ --> $O(n)$ ![](https://i.imgur.com/fuTC0qM.png) ![](https://i.imgur.com/7dxli6Q.png) ![](https://i.imgur.com/hjMquQ9.png) ![](https://i.imgur.com/3wtg4HZ.png) > johnson's algorithm allow negative weights because it will reweight those edges --> but no negative cycle allowed! --> graph may not have cycle --> DAG ![](https://i.imgur.com/P7LUFoW.png) ![](https://i.imgur.com/d4SBdv7.png) ![](https://i.imgur.com/5aXY7hx.png) > 也可用遞迴來想 存在n條線,再加上一條線與這n條都相交 total = $n + n +1$ 故從1開始,是$1 + 2 + 3 + 4 + ... + n = O(n^2)$ ![](https://i.imgur.com/BuOop2I.png) ![](https://i.imgur.com/kS6tkJf.png) ![](https://i.imgur.com/QHgQ19o.png) ![](https://i.imgur.com/TI6lyhS.png) ![](https://i.imgur.com/WJ0MGoK.png) > Johnson's algorithm的正確性: > 1. negative cycle若存在於原本的圖,則用source和weight 0 edge連接每個vertex後,negative cycle繼續存在 > 2. triangle inequality:從 s 到 u 和 s 到 v的shortest path距離,再加上w(u,v),即有不等式,用來reweight,保證reweight後的edge weight > 0 ![](https://i.imgur.com/4zEPJhH.png) ![](https://i.imgur.com/5LhZ8fO.png) > Diffie Hellman (DH) key exchange algorithm 三人以上不適用 ![](https://i.imgur.com/xI3xywN.png) > A van Emde Boas tree (Dutch pronunciation: [vɑn 'ɛmdə 'boːɑs]), also known as a vEB tree or van Emde Boas priority queue, is a tree data structure which implements an associative array with m-bit integer keys. It performs all operations in O(log m) time, or equivalently in O(log log M) time, where M = 2m is the maximum number of elements that can be stored in the tree. The M is not to be confused with the actual number of elements stored in the tree, by which the performance of other tree data-structures is often measured. The vEB tree has good space efficiency when it contains many elements, as discussed below. It was invented by a team led by Dutch computer scientist Peter van Emde Boas in 1975.[1] ![](https://i.imgur.com/i0V8Imo.png) ## others ![](https://i.imgur.com/raNLbKY.png) > 看到要求複雜度$O(1)$,通常就是要用hash > ![](https://i.imgur.com/gzglPb4.png) > ![](https://i.imgur.com/j258Ovd.png) ![](https://i.imgur.com/BzsSsfu.png)

    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