A graph G = (V,E) is composed of

網多實驗 上台報告內容 圖論的基本介紹
電機四 B89901146 陳俊嘉
圖論的一些名詞定義:
A graph G = (V,E) is composed of: (1)V set of vertices (2)E set of edges connecting the
vertices in V
An edge e = (u,v) is a pair of vertices
connected graph: any two vertices are connected by some path
subgraph: subset of vertices and edges forming a graph
tree - connected graph without cycles
forest - collection of trees
A spanning tree of G is a subgraph which is a tree and which contains all vertices of G
What’s a Digraph?
A directed graph!!Each edge goes in one direction. Edge (a,b) goes from a to b, but not b to a
Digraph Applications:
1. Maps: digraphs handle one-way streets(especially helpful in Providence)
2. Scheduling: edge (a,b) means task a must be completed before b can be started
DAG(directed acyclic graph):Say What?! directed graph with no directed cycles!!
Weighted Graphs:weights on the edges of a graph represent distances, costs, etc.
Eulerian Tour: path that traverses every edge exactly once and returns to the first vertex
Euler path = 一筆劃問題!! 如下圖所示:
(右圖為左圖的歐拉路徑)
Euler’s Theorem: A graph has a Eulerian Tour if and only if all vertices have even degree!!
我為什麼要介紹圖論?
圖論在生活上有很多應用!電腦輔助設計電路、網路(道路, 航空,通信)、行程表、
演算法、都市系統結構、建物動線分析、electronic circuits、networks(roads, flights,
communications)、scheduling (project planning)
圖論的數學模型、Data Structures
A Graph! How can we represent it? To start with, we store the vertices and the edges into two
containers, and each edge object has references to the vertices it connects. Additional
structures can be used to perform efficiently the methods of the Graph ADT.
Data Structures for Graphs:
(1) Edge list(2)Adjacency List (traditional)(3)Adjacency List (modern)(4)Adjacency
matrix
Edge List
• The edge list structure simply stores the vertices and the edges into unsorted sequences.
• Easy to implement.
• Finding the edges incident on a given vertex is inefficient since it requires examining the
entire edge sequence
(Figure: Edge List)
Adjacency List (traditional)
• adjacency list of a vertex v: sequence of vertices adjacent to v
• represent the graph by the adjacency lists of all the vertices
(Figure: Adjacency List (traditional))
Adjacency List (modern)
• The adjacency list structure extends the edge list structure by adding incidence containers
to each vertex.
(Figure: Adjacency List (modern))
Adjacency Matrix (traditional)

matrix M with entries for all pairs of vertices



M[i,j] = true means that there is an edge (i,j) in the graph.
M[i,j] = false means that there is no edge (i,j) in the graph.
There is an entry for every possible edge, therefore: Space = O(N2)
(Figure: Adjacency Matrix (traditional))
實際生活中的圖論
哥尼斯堡七橋問題
歐洲的普瑞格爾河(Pregel River)流過東普魯士(East Prussia)的古城哥尼斯堡
(Konigsberg)市中心,河中有兩座島,築有七座古橋,如圖所示。不知何日何人提出
如下的智力問題:請走過每座橋恰一次,再返回出發點。
1736 年,年 29 的數學家歐拉(Euler, 1707-1783)嚴格地證明了上述哥尼斯堡七橋問題
無解,並且由此開創了圖論的典型思維方式及論證方式,1736 年遂被公認為圖論元
年。如圖所示,將橋以線段表示,陸地以點表示,畫成如右圖的圖形,於是哥尼斯
堡七橋問題變轉化為一筆劃問題(歐拉路徑)了!!
哈密頓(Hamilton)周遊世界問題:
1857 年,英國數學家哈密頓發明了一種遊戲:在正十二面體的 20 個頂點上分別標
記 20 個不同的世界著名城市,要求從某城市出發,沿正十二面體的稜邊行走,每城
市恰只經過一次,而且又折返回原出發點。將此問題在紙上畫成網絡圖形,就是右
邊圖的樣子。雖然它看起來不像一個正十二面體,但這對於給出周遊世界問題的解
答沒有任何影響,因為我們所關心的是能否周遊,對於所走的路線是何種形狀,有
多遠,都不是我們過問的事。周遊世界問題屬於走遍各頂點的問題,走遍各頂點的
一般化問題則是當今最難判定的問題之一,至今尚無有效方法來解決!
最短路徑問題 (Shortest Path Problem)
• BFS finds paths with the minimum number of edges from the start vertex
• Hencs, BFS finds shortest paths assuming that each edge has the same weight
• In many applications, e.g., transportation networks, the edges of a graph have different
weights.
• How can we find paths of minimum total weight?
Dijkstra’s Algorithm for Shortest Path Problem
• Dijkstra’s algorithm finds shortest paths from a start vertex v to all the other vertices.
• Requirements: it works on a graph with
– undirected edges
– nonnegative edge weights
Dijkstra’s Algorithm:
The algorithm computes for each vertex u the distance to u from the start vertex v, that is, the
weight of a shortest path between v and u. the algorithm keeps track of the set of vertices for
which the distance has been computed, called the cloud C. Every vertex has a label D
associated with it. For any vertex u, we can refer to its D label as D[u]. D[u] stores an
approximation of the distance between v and u. The algorithm will update a D[u] value when
it finds a shorter path from v to u. When a vertex u is added to the cloud, its label D[u] is equal
to the actual (final) distance between the starting vertex v and vertex u. Initially, we set D[v] = 0 ...the distance from v to itself is 0...
D[u] = ∞ for u ≠ v ...these will change...
Depth-first search (DFS)
A depth-first search (DFS) in an undirected graph G is like wandering in a
labyrinth with a string and a can of red paint without getting lost.
• We start at vertex s, tying the end of our string to the point and painting s
“visited”. Next we label s as our current vertex called u.
• Now we travel along an arbitrary edge (u, v).
• If edge (u, v) leads us to an already visited vertex v we return to u.
• If vertex v is unvisited, we unroll our string and move to v, paint v “visited”, set
v as our current vertex, and repeat the previous steps.
• Eventually, we will get to a point where all incident edges on u lead to visited
vertices.We then backtrack by unrolling our string to a previously visited vertex v. Then
v becomes our current vertex and we repeat the previous steps.
• Then, if we all incident edges on v lead to visited vertices, we backtrack as we did
before. We continue to backtrack along the path we have traveled, finding and
exploring unexplored edges, and repeating the procedure.
• When we backtrack to vertex s and there are no more unexplored edges incident on
s, we have finished our DFS search.
Euler Path and Layout
try to keep your layout compact and rectangular in shape. To make a compact XOR layout,
we would be adopting the Euler Path layout techniques.
An Euler path in a Pull up network (PUN) and Pull down network (PDN) is defined as a path
through all nodes in the graph, such that each edge in the graph is only visited once. Once a
consistent Euler path in the logic graph of the PUN and PDN is identified, the ordering of the
inputs, which results in an uninterrupted diffusion strip of NMOS and PMOS transistors is
determined as well.
An Euler Path layout technique allows you to use single n-diffusion (ndiff) and p-diffusion
(pdiff) strips with single vertical poly for each input in your layout. This is very important
since it results in a very compact and rectangular layout.
x
x
c
b
VDD
x
a
c
b
VD D
x
a
d
GND
d
GND
(a) Logic graphs for (ab+cd)
(b) Euler Paths {a b c d}
VD D
x
GND
a
b
c
d
(c) stick diagram for ordering {a b c d}
Reference:
雷欽隆老師”資料結構”課程投影片
http://access.ee.ntu.edu.tw
http://www.utc.edu/~cpmawata/petersen/
Paper: 沿著歐拉的足跡──圖論初探