Data Structure Lecture Note (Week 5, Lecture 15)

DFS property 1 in SCC

Property1: For a DFS starts within a vertex r in SCC, without a restart, the DFS tree rooted at r will cover all the vertices in SCC.

Pf: because v and r are in the same SCC, r has a path to v in scc, then by the lemma[^remark](The path can consist all kinds of edges) of DFS, v will be in DFS tree rooted at r.

So, how to find all SCC in a DFS?

We should find the lowest component (in topological sort), then do DFS to explore the entire component and restart, each restart should be on the second lowest one, then third … [But this is kinda “chicken and edg” problem]

How to find the lowest SCC

Define reversed graph Gr = (V, Er) where edges are reversed edges of G

Property 1: reveresed graph Gr and G have the same SCCs

Property 2: A minima component in Gr is a maxima component in G, and vice versa

Note we don’t use minimum or maximum here, because some are incomprable in topological sorting.

Start time, end time

Associate a timer with DFS, each step of code is tick up by 1

Start time of a vertex: the timer reading when we first enter the function of exploring the vertex

Finish time of a vertex: the timer reading when we exit from the function of exploring the vertex

Corollary 1: So then FinishTime(v) < FinishTime® in this [the same] DFS, the vertex that is first explored by the DFS within this SCC has the largest finishing time.

Corollary 2: in a directed graph G, if there is a path from u to v but not the other way around, then for any DFS, we have F(u) > F(v)

​ because if u is explored first then v will be explored under the same tree (by the lemma ); if u is explored later than v, naturally F(u) > F(v), since v can get to u in DFS tree.

If F(u) > F(v): case 1 [in one tree], DFS hits u first, then v; case 2 [DFS restarts], DFS restarts at u, but v is visited earlier.

Detecting SCC Algorithm

step1: DFS on Gr

Do a DFS on Gr starting with any vertex, the vertex S that is finished

step2: from s, do DFS again on G

start from the S node we found, do DFS again in G. Then this time we are sure we start from a sink in the G.

Idea: use the finishing time of DGS in Gr to sort


O(E) reverse + O(E) finishing time + O(E) DFS for original graph

Lecture 15: Elementary P vs NP, NP-hardness

A non-formal introduction without using Turing Machine.

We want to classify problems into different classes.

Decision Problems

Optimization Problems

There are many problems that cannot be solved in polynomial time.

3-Sat Problem

You are given boolean formula from conjunction of clauses of N variables and each clause is a disjunction of 3 variables, output YES if there is an assignment of true/false to the varibles that satisfies all the clauses, and output NO if there isn’t any.

[Motivation: Using the laws of Boolean algebra, every propositional logic formula can be transformed into an equivalent conjunctive normal form, which may, however, be exponentially longer.]

very likely, there is no polynomial time algorithm to determine 3-SAT

If you enumerate 2^k you can brutally solve it.

Independent Set problem

Decision version: whether there exists an independent set of size k in a graph G = (V, E), where independent set S ⊂ V S\subset V SV is defined as for any pair of vertices in S, there is no edge between them.

Optimization version: given a graph, find the largest independent set in the graph.

[application: in social network, find groups people know each other]

[A set is independent if and only if it is a clique in the graph’s complement]

Vertex cover problem

Decision version: whether there exists a cover set of size k for a given graph G = (V, E), where cover set S is a subset of V, such that for all edges in E, there is at least one end point in S

Optimization version: find the minimum cover set for a given graph G

Clique Problem

Decision version: whether there exists a clique of size k for a given graph G = (V, E), where clique C is a subset of vertices, such there are edges between every pair of vertices in C.

Optimization version: find the maximum clique of given graph G.

Class of problems

Easy problems, problems that can be solved by polynomial time algorithms

Hard problems, problems that are UNLIKELY to be solved by polynomial time algorithms.

  • Deterministic polynomial time solvable §
  • Non-deterministic polynomial time solvable (NP)
  • NP ? P

$P\subset NP, but P? NP $

Limiting ourselves to decision problems

Finite many solutions; each solution is of polynomial length; each solution can be checked in polynomial time; checking happens simultaneously

  1. Finite many solutions;
  2. each solution is of polynomial length;
  3. each solution can be checked in polynomial time;
  4. checking happens simultaneously
  5. Don’t need to enumerate solutions. Or enumeations happen at the same time

i.e. To argue a problem is NP is simple. As long as you can guess.

Reduction.

A problem is called NP hard, if any other NP problem can be reduced to this problem

Reduction

Definition of reduction algorithm R: for an input j of problem A, we can transform j into R(j) which is an input of problem B, then use X to solve the problem R(j): provide an yes/no, if yes, then j is also a yes for A, if no, then j is a no for A

problem A can be reduced in polynomial time to problem B: if there is a polynomial time reduction algorithm from A to B

written as A ≤ R B A\le_R B ARB

Motivation: if B is solvable by a polynomial time algorithm X, then A can also be solvable by a polynomial time algorithm X_R

X_R is formed by combining R and X together we can have a polynomial time algorithm to solve A.

Property: If problem X is NP-hard, and X can be reduced to Y, then Y is also NP-hard.

Property: If problem A ≤ R 1 \le_{R_1} R1 problem B and problem B ≤ R 2 \le_{R_2} R2 problem C, then problem A is reducible to problem C by compounding two reductions together.

Let’s assume we know independent set problem is a NP-hard problem

now, let’s prove that cover set problem is a NP-hard problem

Reduction: Clique Problem to independent set

So we assume that we have a polynomial time algorithm for independent set problem and we want to find an reduction algorithm R from clique problem to independent sets such that the instance of clique problem is an YES instance iff the instance of the independent set problem is a YES instance.

For each G = (V, E) we want to convert it to another graph H such that G has a clique of size K iff H has an independent set of size K.

Idea: complement of G = (V, E)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值