The history of Graph Store(matrix, adjacency list, and orthogonal list)
来源:互联网 发布:小米摄像头app软件 编辑:程序博客网 时间:2024/04/30 17:33
common problems. i.e..shorest path problem, minimum spanning tree, and so on. In addition
,we could effective extend this ability by the help of computer. Before that, a necessary
problem is: How can we store a graph to a computer ? which data structure is more appropriate?
There are some common data structures used to solve this problem. In this article, we
discuss three of them: adjacency matrix, adjacency list, and orthogonal list. But before that, let
us build a simple graph. It will be used by the following examples.
5
a-----------------d
|\ 1 |
| \ |
4 | c | 3
| / \ 2 |
|/2 \ e
b f
1. Adjacency matrix
In this structure, we use a two-dimention array to save all information. It is simple. Actually,
even a example is enough to explain how to use this method. The following is the graph above
represented as adjacency matrix.
a b c d e f
a 0 4 1 5 U U
b 4 0 2 U U U
c 1 2 0 U U 2
d 5 U U 0 3 U
e U U U 3 0 U
f U U 2 U U 0
In this array, A[i][j] means the edge weight from node i to node j. Because this is a undirected
graph, the array is symmetric. As we can see, there is a obvious disadvantage in this method
is that there are many position is empty. Any advices to save this problem ? See next section.
2. Adjacency List
Actually, at first sight, I thought maybe a mutiple linked list is a good choice. But It is not
as simple as I thought. A key point is that the degree of a node is indeterminate. Some of nodes
have a few of edges. But another have many. So maybe we need build a special list.
Adjacency list is what we want. It provide a nice solution to this problem. If we use the
graph above , we could get a adjacency list like this:
[node a] --> ( edge to b) --> (edge to c) --> (edge to d)
[node b] --> ( edge to a) --> (edge to c)
[node c] --> ( edge to a) --> (edge to b) --> (edge to f)
[node d] --> ( edge to a) --> (edge to e)
[node e] --> ( edge to d)
[node f] --> (edge to c)
In C, maybe the following structure is a example to build a adjacency list.
struct NODE {
struct EDGE *next;
};
struct EDGE {
struct EDGE *next;
struct NODE *node;
};
Compare with the adjacency matrix, the advantage of adjacency list is that there is no
empty item. For those graph which have a few of edges, it is usefull. Of curse, the data
structure is become more complex. And still have some problem. Sometime, we need to find
the in-degree or out-degree of a node. If the graph is a undirected, all is ok. But if it is a
directed graph, that will be different. Based on our define for adjacency list, the list of a
node is only contain of out-degree,there are no information about in-degree. That means
we must travel all over the adjacency list if we want to get the in-degree. That is awful.
So we build another adjacency list by reverse the define of normal one, it is called reverse
adjacency list. Like this
[node a] --> (edge from b) --> (edge from c) --> (edge from d)
[node b] --> (edge from a) --> (edge from c)
[node c] --> (edge from a) --> (edge from b) --> (edge from f)
[node d] --> (edge from a) --> (edge from e)
[node e] --> (edge from d)
[node f] --> (edge from c)
As we can see,we will convenient to get in-degree in reverse adjacency list.
3. Orthogonal list
For solve the problem, we introduce a new data structure--cross list.
[node a] [node b] [node c] [node d] [node e] [node f]
| | | | | |
[node a]-------------(edge to b)--(edge to c)--(edge to d)------------------
| | | | | |
[node b]--(edge to a)-------------(edge to c) -------------------------------
| | | | | |
[node c]--(edge to a)--(edge to b)---------------------------------(edge to f)
| | | | | |
[node d]--(edge to a)-----------------------------------(edge to e)----------
| | | | | |
[node e]-----------------------------------(edge to d)--------------------
| | | | | |
[node f]-------------------------(edge to c)-------------------------------
| | | | | |
It is similar with the adjacency matrix.the different between them is that we use a
multilist in orthogonal list. The use of list help us skip "the empty item" in adjacence matrix.
That is nice!! But the cost is we need more space to save the information about coordinates.
It is necessary. For example: if we want to ensure the status between node c and node b,
it is difficult to find the corresponding edge without the flag information. Based on our analysis,
we could build a example in C.
struct NODE {
struct EDGE *next;
};
struct EDGE {
int x;
int y;
struct EDGE *line;
struct EDGE *row;
};
4. Recall
Recall our history of solve problems, we was introduce adjacency matrix for saveinformation about graph. Then we found a problem: there are some empty item in the
adjacency matrix. when the degree of the node is few, the situation become insufferable.
So we was introduce a new data structure--adjacency list. It has been solve the problem
about empty item. But introduce another problem, It is difficult to get both in-degree and
out-degree in a single list. For solve this problem, we introduce another data structure
--orthogonal list. To some extent, this is nice.
- The history of Graph Store(matrix, adjacency list, and orthogonal list)
- Graph Theory Adjacency List.解释
- Adjacency Matrix of Graph(图的邻接矩阵)
- orthogonal list
- Adjacency List Dijkstra
- session store list and show in the jsp
- Book List of Graph Theory
- 十字链表 Orthogonal List
- 图(有向图)的邻接表表示 C++实现(遍历,拓扑排序,最短路径,最小生成树) Implement of digraph and undigraph using adjacency list
- GeeksforGeeks - Adjacency List邻接矩阵C\C++代码
- Adjacency list追溯到源头的方法
- List of X$ Tables and how the names are derived
- The 2015 Concise List of Hacker Tools and videos
- The History of Notes and Domino
- Customs and history of the origin of the Mid-Autum
- usage of list and iterator
- The list of Vim commands
- The list of Vim commands
- [LeetCode] Unique Binary Search Trees
- 关于关键字ref和out
- cin问题
- 题目1196:成绩排序
- 2014多校1(1006)hdu4866
- The history of Graph Store(matrix, adjacency list, and orthogonal list)
- hdu 4419
- 开源爬虫软件汇总
- git-cola的安装(SIP + QT4 + PyQt)
- java实现局域网内多人群聊
- BOJ 469. 暑假作业题
- 设计一个Cache系统 【双向链表+哈希表】
- Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest
- POJ 1159 Palindrome 题解