or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
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.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
演算法 - 荊宇泰 (2022 Fall)
tags:
NYCU-2022-Fall
Class info.
課程資訊
One midterm exam, one final exam (70% of final score).
At most 3 programming assignments, some homework (reading assignments), and some quizs.
Date
9/16
課程介紹,期中要多努力,期末難
9/23
In Computer Science, computer algorithms defined under the Random Access Machine (RAM) model. RAM, Random Access Machine, there are finite number of instructions, \(+, -, *, ...\).
These instructions are basic enough (assembly language of X86).
Correctness of algorithm doesn’t imply the correctness of the program.
Calculate the number of operations required and present the time required as a function of the input size.
Worst case, each time you have a key which is smallest among the previous sorted list, and thus you have to compare all.
Generally follow the worst case convention.
Θ-Notation, asymptotic tight bound
Given a function \(g(n), Θ(g(n))\) is the set of functions, \(Θ(g(n)) = \{f (n) \ | \ ∃ \ positive \ constants \ c_1, c_2, and \ n_0 \ s.t. \ 0 ≤ c_1 · g(n) ≤ f (n) ≤ c_2 · g(n), ∀n > n_0\}\)
9/30
\(\theta(n^2) \ \newcommand*\xor{\oplus} \ \rm{O}(n^2) \rightarrow \theta(n^2)\)
兩集合取交集
Insertion Sort
stable
Selection Sort
stable(老師說的"當=時就交換就能簡單變成stable",但查到的都unstable)
Binary Search
Merge Sort
stable
Divide and Conquer
Divide and Conquer
Homework assignment: Prove the master theorm in the book
(check between simplified master theorem) \(LaTex \rightarrow Overleaf\)
Quick Sort
unstable
only Divide
Quick Sort Pseudocode
Quick Sort provement
為了避免recursion太多導致負擔太大
可以設定當subproblem的長度小於x時使用insertion sort
以及為了減少worst case的發生 (T(n)=T(n-1)+n) => O(n^2))
使用Randomized Quick Sort隨機切分成兩個subproblem
例如T(n)=T(n/4)+T(3n/4)+n => O(nlogn)
但這方法仍可能有worst case
Analysis of Quick Sort
用Random Variable
10/7
Heap
Complete binary tree:
Full binary tree + leaf全靠左
Heap Sort
unstable
Counting Sort
stable
Radix Sort
stable
針對一堆整數,從最小位數到最小位數做Counting Sort
為啥這樣有效?
prove by induction:
induction on digit(位數)
假設後面i位都排好,考慮i+1位時,若兩筆資料大小不一樣則排序完成,否則兩筆資料一樣,則根據Counting Sort是stable的特性,後面i位數也都會是排好的。
Largest Gap in an array \(O(N)\)
非max-gap,關於min-gap/max-gap在Other Problem
Homework assignment: Leetcode K closet pair in \(\rm{O}(nlogn)\)
Using C/C++ as language
10/14
Selection Problem
若要找第i大的數字,使用sorting來解的話會保證O(nlogn),為何是big-O而非big-omega?因為這個問題可能有非sorting的解法。
找最大、最小數是theta(n)因為必定要跟n-1個數字比較
但是同時找最大最小只需要3ceiling(n/2)而非2n-2
不過老師說他不知道怎做的不是重點
Homework assignment: Prove un-used nodes always more than used nodes
CLRS answer
期中考11月第一周 (11/4)
考題範圍:
10/21
2-3-4 tree vs red black tree
One disadvantage for using 2-3-4 tree is that there will have lots of nodes which are unused.
Waste memory, comparing with red balck tree.
Concatenable queue



This data structure can execute concatenate() and split() in O(logn)
Development of the dynamic programming algorithm is broken into
a sequence of 4 steps.
Random Variable
The hiring problem
機率、期望值
Other Problem
Max-gap/Min-gap
把所有資料normalization((k-min)/(max-min))後
放入一個個bucket中
根據鴿籠原理必有一個bucket是空的
而Max-gap必定橫跨這個空bucket
接著用O(n)把所有bucket中最大最小的值找出來
再把最大跟最小兩兩配對算距離(最多n個)即可找到Max-gap
花花酱 LeetCode 164. Maximum Gap
11/11
Greedy Algorithm
Amortized Analysis
Homework 03 Table Expansion and Contraction proof
原文書 17.4 Dynamic tables
some info.
some powerpoint
11/18
Union and Find
Binomial Heap / Fibonacci Heap
期末整理
期末考 (12/30)
考題範圍:
螢光的有考
部份參考解答
Greedy algorithm
Activity-Selection problem
Dynamic Programming approach
Define \(\mathcal{S}_{i, j} = \{ a_k \in \mathcal{S} \ | \ f_i \lt s_k \lt f_k \le s_j \}\)
Add activities \(a_0\) and \(a_{n + 1}\), \(f_0\) = 0, \(s_{n+1} = \infty\)
The substructure of the optimal solution
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Theorem
Consider a nonempty subproblem \(\mathcal{S}_{i, j}\) with earliest finish time \(f_m = \min \{ f_k \ | \ a_k \in \mathcal{S}_{i, j}\}\). Then
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Greedy approach
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Knapsack problem
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Huffman Code
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Prefix Code
Proof of the Greedy Choice Property
Proof of the Optimal substructure property
Amortized Analysis
Resource
CLRS with notes
YT Course
Aggregate Method
Determine an upper bound \(T(n)\) for \(n\) operations. Amortized cost is \(\frac{T(n)}{n}\).
Accounting Method
Potential Method
\[ \begin{aligned} \sum_{i=1}^n \hat{c}_i & =\sum_{i=1}^n\left(c_i+\Phi\left(D_i\right)-\Phi\left(D_{i-1}\right)\right) \\ & =\sum_{n=1}^n c_i+\Phi\left(D_n\right)-\Phi\left(D_0\right) \end{aligned} \]
Stack operation
Aggregate method
Accounting Method
So I prepay 2 dollars to the person move plates to the stack.
Potential Method
Incrementing a Binary Counter
Aggregate method
Accounting Method
Potential Method
Dynamic Table
Table Expansion, while inserting ith item
Aggregate Method
Accounting Method
Potential Method
Table Expansion
If the ith operation trigger expansion, the \(size_i = 2 \cdot size_{i-1}\)
and \(size_{i-1} = num_{i-1} = num_{i} - 1\), which implies that \(size_i = 2 \cdot (num_i - 1)\)
\(\begin{aligned} \hat{c}_i & =c_i+\Phi_i-\Phi_{i-1} \\ & =\text { num }_i+\left(2 \cdot \text { num }_i-\text { size }_i\right)-\left(2 \cdot \text { num }_{i-1}-\text { size }_{i-1}\right) \\ & =\text { num }_i+\left(2 \cdot \text { num }_i-\left(2 \text { num }_i-2\right)\right)-\left(2\left(\text { num }_i - 1 \right)-\left(\text { num }_i-1\right)\right) \\ & =\text { num }_i+2-\left(\text { num }_i-1\right) \\ & =3 .\end{aligned}\)
Table Expansion and Contraction
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →MergeableHeaps
Properties of binomial trees (provement)
\(\Rightarrow\) Proof Immediate from Properties 1 and 4 of previous lemma.
Binomial Heap
Fibonacci heap
YT Course
Union and Find
CLRS Notes
Prove the Time Bound (Amortized Analysis)
Graph
Sorting Network
A comparator, a comparison is done in constant time.
Zero-One Principle
Bitonic Sorting Network
Merging Network
NP
Select Topics Note
Reference
原文書電子檔
原文書解答
筆記 1
筆記 2