Linked list from a graph-theoretic viewpoint
As you may have known before, graphs and other related structures (e.g. trees, binary trees, etc.) help us to construct effective methods to store and search for data. In fact, linked list and its variations can also be viewed graph-theoretically.
A linked list is a list of objects constructed as follows: starting from an object, called the head, we continuingly insert the succeeding objects until we reach the final object, called the tail. In this list, an object is linked to its succeeding object. More clearly, this list consists of n objects, namely o(1), o(2), ..., o(n) such that for each i = 1, 2, ..., n - 1, o(i) is linked to o(i + 1). We can associate this list with a graph as follows: the vertices of the graph are o(1), o(2), ..., o(n) and A is adjacent to B if and only if A is linked to B. Here is the graph for n = 6. In graph theory, this graph is called a directed path.
1. Directed graph
A directed graph is an ordered pair G = (V, A), where V is the vertex set and A is a family of ordered pairs of elements from V. In a directed graph, adjacency is not symmetric or mutual. For example, in the following directed graph, 1 is adjacent to 2 but 2 is not adjacent to 1.
2. Linked list and the associated directed graph
A linked list is a list of objects constructed as follows: starting from an object, called the head, we continuingly insert the succeeding objects until we reach the final object, called the tail. In this list, an object is linked to its succeeding object. More clearly, this list consists of n objects, namely o(1), o(2), ..., o(n) such that for each i = 1, 2, ..., n - 1, o(i) is linked to o(i + 1). We can associate this list with a graph as follows: the vertices of the graph are o(1), o(2), ..., o(n) and A is adjacent to B if and only if A is linked to B. Here is the graph for n = 6. In graph theory, this graph is called a directed path.

There are two variations of the linked list: circular linked list and doubly linked list. The circular linked list is obtained from the linked list by linking o(n) with o(1). As a result, the associated graph becomes a directed cycle (since we add a directed arc/edge from o(n) to o(1)) instead of a directed path, as shown in the image below.
A doubly linked list is a list such that for each i, o(i) is linked to o(i + 1) and conversely, o(i + 1) is linked to o(i). The associated graph is as follows, which can be considered as an undirected graph/path. However, to illustrate more clearly, two arrows in opposite directions will be drawn for each pair o(i), o(i + 1). In fact, when declaring the doubly linked list, two directed edges should be indicated for each such pair.



Nhận xét
Đăng nhận xét