AIdrifter
    • 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
    # [AIdrifter CS 浮生筆錄](https://hackmd.io/s/rypeUnYSb) <br> Cracking The Coding interview # 前言準備 - google注重system design和可擴展性 - C++ - Professional - 精通 - 用過 - OPL , TA stack-usage - Challenge - mistake / fault - 收穫 - 領導 - Conflict - 現在想想是否有不同的做法 ![](https://i.imgur.com/PvWu6U2.png) ![](https://i.imgur.com/m2homyw.png) - 盡量不要說"我們",人家會搞不楚這東西到底是不是你做的 - SAR - Situation - Action - 拆順序,分散步驟,最重要的部分。 - Result :::info 之前P&P Language上課的Job Interveiw ::: # Big-O ## Asymptopic Notation 業界Big-O <=> 學術Big-Theta 課本 - Big O - Big Theta - Big Omega ## Time Complexity O(n) : constant time O(logn) : logarithmic : 通常是binary Search,元素折半。 O(n) : linear O(nlogn) : linearithmic O(n^2) : square O(n^3) : cubic O(2^n) : exponetial : fib(n) = fib(n-1) +fib(n-2), O(branch^depth),看不懂可以畫tree圖。 O(n!) : factorial ![](https://i.imgur.com/2mRtBTd.png) quick sort - Best O(n) - Worst O(n^2) - Average (nlogn) - 這些說的都是big-thetas https://en.wikipedia.org/wiki/Time_complexity ## Sapce Complexity - Recursive stack ## Amortized Time 平攤時間 - Vector insert()時的copy元素成本 ``` 1 + 2 + 4 + 8 + ....x = x + x/2 + x/4 + ... 1 = x(1 + 1/2 + 1/4 + .... 1/2^n) = x( 1/( 1- 1/2)) = 2x ``` ![](https://i.imgur.com/lNzykWp.png) ## f(n) = f(n-1) + f(n-2) Time Complexity : O(2^n) : O(branch^depth) Sapce Complexity: O(n) : Tree height 1+2+3+...n = n(n+1)/2 ![](https://i.imgur.com/EmVX8Cr.png) ![](https://i.imgur.com/wGnTntA.png) O(branch^depth) => O (2^logn) = O(n) // 換底公式 2^p = Q => lnQ = P :::info 延伸題目 1.用binary Search找平方根 2.Permutation的recursive寫法 ::: # Technicla Questions ## 必會章節 ![](https://i.imgur.com/iEJktUk.png) ## 解題步驟 ![](https://i.imgur.com/jAHCUqc.png) ## BUD ![](https://i.imgur.com/Vq6lrlr.png) ## BCR Best Conceivable Runtime https://hackmd.io/CSJhi7AaTkmoT4pLOUR2RA ## What Good Coding Looks Like ![](https://i.imgur.com/ptTj2Vq.png) ![](https://i.imgur.com/b3JdCbO.png) ![](https://i.imgur.com/y7iBbQ6.png) - 用資料結構去存資料:Coeficcient - Appropriate Code Reuse - ![](https://i.imgur.com/YR6KSaj.png) - Modular - function化 : 多寫幾個function - Flexible and Robust ![](https://i.imgur.com/JGiGvcp.png) # Array & String :::info Review Previous STL all time Complexity ::: ## Hash Table ![](https://i.imgur.com/tdpobtq.png) ## Array List Java: ArrayList <=> C++: vector ## String Builder Java:StringBuilder ![](https://i.imgur.com/5U9VSR2.png) https://stackoverflow.com/questions/2462951/c-equivalent-of-stringbuffer-stringbuilder :::info C++的stringBuilder??? ::: # LinkedList - Insert() - Delete() - If the list is doubly linked, we must also update n. next to set n. next. prey equal to n. prev. ![](https://i.imgur.com/vmiCYls.png) - runner(): 龜兔賽跑 找迴圈 - Recursive Problem # Stack LIFO - push() - peak() <=> top() - pop() - IsEmpty() - Application - DFS - recursive # Queue - add() - remove() - peak - IsEmpty() :::info - Priority queue + heap ::: - Application - BFS - 實做cache # Tree Binary Tree Full Binary Tree: 每個node都有兩個child ![](https://i.imgur.com/LoUYBrb.png) Complete Binary Tree: 從左到奏照順序擺: heap ![](https://i.imgur.com/nG5fQlo.png) Ternay Tree Binary Search Tree Balanced Tree Perfect Tree: every level has full nodes ![](https://i.imgur.com/ErR1Ll2.png) ## Tree Traversal :::info 要有全部Traversal的實做 DLR LDR LRD ::: ![](https://i.imgur.com/P7jE70R.png) - in-order traversal - Typically, for binary search tree, we can retrieve all the data in sorted order using in-order traversal. We will mention that again in another card(Introduction to Data Structure - Binary Search Tree). - post-order traversal - is widely use in mathematical expression. It is easier to write a program to parse a post-order expression. Here is an example: - ![](https://i.imgur.com/OjAWf4k.png) ```C++ vector<int> inorderTraversal(TreeNode* root) { vector<int> result; TreeNode* visit = root; stack<TreeNode*> stree; while (visit != NULL || !stree.empty()) { if (visit != NULL) { stree.push(visit); visit = visit->left; } else { visit = stree.top(); stree.pop(); result.push_back(visit->val); visit = visit->right; } } return result; } ``` ```C++ lass Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> res; stack<TreeNode*> stk; TreeNode* temp = root; while(temp != NULL || stk.empty() == false) { while(temp != NULL) { stk.push(temp); temp = temp->left; } temp = stk.top(); stk.pop(); res.push_back(temp->val); temp = temp->right; } return res; } }; ``` ```C++ for (std::stack<TreeNode*> dump = st; !dump.empty(); dump.pop()) std::cout << dump.top()->val << " "; cout<<endl; ``` ```C++ vector<int> postorderTraversal(TreeNode* root) { if(!root) return {}; stack<TreeNode*> st; TreeNode* visit = root; vector<int> path; st.push(visit); while(!st.empty()){ visit = st.top(); st.pop(); path.push_back(visit->val); if(visit->left) st.push(visit->left); if(visit->right) st.push(visit->right); } reverse(path.begin(), path.end()); return path; } ``` https://leetcode.com/explore/learn/card/data-structure-tree/134/traverse-a-tree/930/discuss/45551/Preorder-Inorder-and-Postorder-Iteratively-Summarization ## Binary Heaps :::info 要有Priority Queue的實做 ::: ### Insert() + adjust() ![](https://i.imgur.com/1ii8mAS.png) ### extract_min() + adjust() ![](https://i.imgur.com/TowHFo4.png) ## Tries (Prefix Tree) - N-ary Tree的變形 ![](https://i.imgur.com/m99Vphy.png) ## Red-Black Tree # Graph ## adjancey List ## adjancey matrix ## BFS BFS + queue - width/breadth - horizontal - visit every nodes ![](https://i.imgur.com/4IUisCX.png) ## DFS DFS + stack - vertical - 兩點間的最短距離 ![](https://i.imgur.com/OjcYzB6.png) ## Bidirectional Search ![](https://i.imgur.com/7Es92vH.png) ![](https://i.imgur.com/ogXwX7R.png) ## Algo ### Floyd-Warshall 求全部的點到點最短距離O(n^3) ### Topological Sort ### Dijkstra ### AVL Tree # Bit Operation ## 技巧 ## Arthimeticvs vs. Logical right Shift ![](https://i.imgur.com/m6H1f4l.png) ![](https://i.imgur.com/4gYFqcj.png) ![](https://i.imgur.com/CzHDioE.png) ## Common Bits Tasks ### Get ### Set(set 1) ### Clear(set 0 from 0 to i) ![](https://i.imgur.com/vwqmVv2.png) ### Update(set 0 or 1) ![](https://i.imgur.com/k1u7QKe.png) # Mathematics ## Prime ### sqrt(n) a*b = n ,必存在b任一數使得 b<sqrt(n) ### The Sieve of Eratosthenes :::info code... ::: ## gcd greatest common divisor ## lcm least common mutiple xy = gcd(x,y) * lcm(x,y) ![](https://i.imgur.com/ZYIoXD5.png) ## Probability ![](https://i.imgur.com/1gMTnPs.png) ### Probability of A and B ### Probability of A or B ### Independence ### Mutual Exclusivity :::info 找時間補一下條件機率 ::: # Logical Puzzles ## Develop Rules and Patterns 兩條線可以燒1hr 如何算出15min ## Worst Case Shifting 九球一球輕 最多稱兩次天平 如何找出最輕球? # Design ## Singleton ## Factory # Recursive + DP ## Approach Top-Down : Recursive Bottom-up : DP(Dynamic Programming) Half-and-Half : Binary Search ## fib ### Recursive ![](https://i.imgur.com/Dan0BNz.png) ### Cache ![](https://i.imgur.com/WEdA19y.png) ### DP ![](https://i.imgur.com/Jrm1R5H.png) # Sort ## Bubble Sort ## Selection Sort ## Merge Sort ## Quick Sort ## Radix Sort(Bucket Sort) - counting sort為弱化版 並沒有處理digits # Search ## Binary Search

    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