Design and Analysis of Algorithms (Interval Scheduling)

Very similar problems can have different complexity. Recall:

  • P: a class of problems solvable in polynomial time. O(n^{k} ) for some constant k.
  • NP: a class of problems verifiable in polynomial time. 

Hamiltonian cycle in a directed graph G(V, E) is a simple cycle that contains each vertex in V. 

Determining whether a graph has a Hamiltonian cycle is NP-complete but verifying that a cycle is hamiltonian is easy.

  • NP-complete: the problem is in NP and is as hard as any problem in NP.

If any NPC problem can be solved in polynomial time, then every problem in NP has a polynomial time solution. 

Interval Scheduling

Requests 1, 2, . . . , n, single resource

s(i) start time, f(i) finish time, s(i) < f(i) (start time must be less than finish time for a request)

Two requests i and j are compatible if they don’t overlap, i.e., f(i) ≤ s(j) or f(j) ≤ s(i).

Goal: Select a compatible subset of requests of maximum size.

Claim: We can solve this by using a greedy algorithm. A greedy algorithm is a myopic algorithm that processes the input one piece at a time with no apparent look ahead.

Greedy Interval Scheduling

  1. Use a simple rule to select a request i
  2. Reject all requests incompatible with i.
  3. Repeat until all requests are processed.

Weighted Interval Scheduling

Each request i has weight w(i). Schedule subset of requests that are non-overlapping with maximum weight

Dynamic Programming

We can define our sub-problems as

Rx = {j ∈ R|s(j) ≥ x}

Here, R is the set of all requests.

If we set x = f(i), then Rx is the set of requests later than request i.

Total number of sub-problems = n (one for each request)

Only need to solve each subproblem once and memorize.

We try each request i as a possible first. If we pick a request as the first, then the remaining requests are R^{f(i)}.

Note that even though there may be requests compatible with i that are not in Rf(i), we are picking i as the first request, i.e., we are going in order.

opt(R) = max (w(i) + opt(Rf(i) )) 1≤i≤n Total running time is O(n2) since we need O(n) time to solve each sub-problem.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值