# Graph
## path
- a sequence P of nodes v1, v2, ..., vk-1, vk with the property that each consecutive pair vi, vi+1 is joined by an edge in E.
- simple: path上沒有重複走過的點(distinct)
- cycle: path至少多於2個點,頭尾相連,中間的點distinct
- connected: 如果任意點到任意點之間都有path,則graph is connected
- distance: minimum number of edges in a u-v path
## tree
- An undirected graph is a tree if it is **connected** and does **not contain a cycle**
- G若滿足兩個條件即為樹:
- G is connected.
- G does not contain a cycle.
- G has n-1
# Greedy Algorithm
## Concept
- builds up a solution in small steps, **choosing a decision at each step myopically** to optimize some underlying criterion
- Intuitive and fast
- Usually not optimal
- prove optimality
1. The greedy algorithm stays ahead.
2. An exchange argument.
## Interval Scheduling Problem
- Given: Set of requests {1, 2, ..., n}, ith request corresponds to an interval with start time s(i) and finish time f(i)
- interval i: $[s(i), f(i))$
- Find a compatible subset