Data Structure Lecture Note (Week 5, Lecture 14)

Directed Graph

A directed graph G = (V, E) is a graph such that E is not necessarily symmetric.

Topological Sorting

We want to figure out an ordering < of vertices such that:

If A < B, then A can reach B by a path but B can’t reach A by a path.

If such an ordering exists, the directed graph G can be topologically sorted. [If 1<–>2, then the graph can’t be topologically sorted(in this version of def)]

  1. Can we tell if a graph can be topologically sorted?
  2. If yes, how can we find a way?

Acyclic Graph

if there if no path in the graph such that the path form a cycle

Property: A directed graph G can be topologically sorted if and only if the graph is an acyclic graph

“if”: we will design an algorithm to do it.

“only if”: by the def, then for any pair (a,b) of vertices, we cannot have both a can get to b by a path, and b can get to a by a path. [just by definition, then this direction of proof is done]


We can then define:

  • sinks (maxima) as out-degree 0 vertices
  • sources (minima) as in-degree 0 vertices
  • Sinks and sources are not necessarily unique
  1. Let S = V
  2. Start from a source vertex v in S with only edges going out
  3. Remove v out of S, and remove the edges related to v out of E, and repeat 1 until S is empty. The order of removal of v is a valid topological sort of the vertices V

Claim: If

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值