O(n2):
O(n log n):
multiple resources
use as few resources as possible
a.k.a. the interval coloring problem: one resource = one color
Given: Set of requests {1, 2, …, n}, ith request corresponds an interval with start time s(i) and finish time f(i)
Goal: Partition these requests into a minimum number of compatible subsets, each corresponds to one resource
depth: a set of intervals is the maximum number that pass over any single point on the time-line.
Lemma: 在interval partitioning的問題下,總共所需資源至少為depth (lower bound)
Use only d resources (depth) to schedule all requests
Greedy Algorithm
找出depth:
Optimality
Interval graph (Intersection graph)
Given:
Goal:
Correctness
假設|S| = k ≥ 1時敘述為真
令下一個要被放進S的node為v,(u, v)為從s到v的最短路徑Pv的最後一段edge,Pv = Pu + (u, v)
根據假設,因u已經在S內,Pu為s到u的最短路徑
考慮其他從s到v路徑的可能路徑P,此路徑必會跨越S與不是S的點,另x為交界處S內的點,y為交界處S外的點
因為line 4會選擇d'(v) = (d(u)+le)最短的v點放入S,所以P不可能比Pv還短
Implementation
Given: Undirected graph G = (V, E)
cost ce for each edge e = (u, v) V
Goal:
(V, T)會是什麼?
Greedy Algorithms
Kruskal's algorithm
Prim's algorithm: (c.f. Dijkstra’s algorithm)
Reverse-delete algorithm: (reverse of Kruskal’s algorithm)
Cut Property
T為一個任意的spanning tree而且沒有包含e,希望證明T不是MST
T為spanning tree,T一定至少有一條edge e'通過subset交界,e'=(v',w'),v' S and w' V–S
T' = T – {e'} + {e}是spanning tree
Cycle Property
Implementing MST Algorithms
Disjoint sets: elements are disjoint
每個set有一個代表
Operations:
Implementation: disjoint-set forest
Running time: union by rank + path compression
Implementing Kruskal’s Algorithm