algorithm

神奇的演算法 - 分組的好朋友 Union Find

category: algorithm     3 minute read     Posted on:

Introduction to Union Find Disjoint Set 是一種資料結構,用來管理一組互不相交的集合(disjoint sets)。每個集合中的元素都是唯一的,且不同集合之間沒有共同的元素。

神奇的演算法 - Binary Search 到底怎麼寫才會對?

category: algorithm     4 minute read     Posted on:

Introduction to Binary Search 如果說,要在一串排序過後的陣列中,找尋特定的數值,二元搜尋絕對是最快的存在 憑藉著一次可以排除一半的可能性,使得二元搜尋的複雜度為 O(log n)

神奇的演算法 - 為什麼你的 Priority Queue 那麼慢!

category: algorithm     4 minute read     Posted on:

Introduction to Priority Queue 針對需要存取一個陣列內,最大或最小值的方法,常見的第一直覺是 sorting 但每次存取每次排序顯然不好,於是有了 Priority Queue 這個資料結構

神奇的演算法 - 動態規劃 Dynamic Programming

category: algorithm     5 minute read     Posted on:

Preface 動態規劃一直是我覺的不容易掌握的演算法技巧,它不像其他演算法技巧有一個固定的模式,而是一種思維方式 題目的靈活性高,不太容易掌握

神奇的演算法 - Greedy Algorithm

category: algorithm     2 minute read     Posted on:

Preface 還記得之前上演算法的時候,最看不懂的東西就是貪婪法了 不過其實他的核心概念很簡單,寫起來也簡單 趁著還記得細節的時候,把它紀錄起來

神奇的演算法 - Backtracking 與 Divide and Conquer

category: algorithm     1 minute read     Posted on:

Algorithm Brainstorming 直接看題目比較快,LeetCode 93. Restore IP Addresses 根據題目要求,給定一個只有數字的字串,找出所有合法的 ip address 的組合

神奇的演算法 - Monotonic Stack

category: algorithm     3 minute read     Posted on:

Preface 千言萬語都比不上一個真實的範例

神奇的演算法 - Binary Indexed Tree

category: algorithm     3 minute read     Posted on:

Binary Indexed Tree 又名 Fenwick Tree, 是一種特殊資料結構,適用於需要大範圍的紀錄更新資料 像是下圖,假設我想要知道,達到 20% 採購率有哪些國家,達到 50% 的又有哪些 一般的作法是我可能開一個 map 去紀錄對吧 看起來會像以下這樣

神奇的演算法 - Subarray Sum

category: algorithm     7 minute read     Posted on:

Subarray Definition subarray 為一個 array 的連續子集合 subarray 不可為空,subarray sum 則為這個子陣列的和