adjacency list and adjacency matrix are able to logically present a non-linear data structure

点点圈 提交于 2021-02-04 21:06:56

问题


how adjacency list and adjacency matrix are able to logically present a non-linear data structure, even though they are themselves linear. Someone Pls explain


回答1:


Stacks, queues, lists, vectors/arrays: they all store data linearly in the sense that items are stored one after the other. There is the notion of "item A comes before item B", and "item C comes after item B". One before, one after. They only differ in how items can be accessed (FIFO, LIFO, by rank, by position).

Trees (a type of graph) store data hierarchically. There's not really a before/after relation. Instead, items are stored based on a parent/child relationship. Then, we can say "the parent of item A is B", and "the children of item A are B, C, D, and E".

Graphs store any type of relation between elements. An item can be related to any other item, as expressed by an edge. We can say "item A is related to B, C, D, E" and "item B is related to A and F". It is in this sense that they are nonlinear. An adjacency list and adjacency matrix accomplish this by, effectively, maintaining a (linear) list of these relationships.



来源:https://stackoverflow.com/questions/61798347/adjacency-list-and-adjacency-matrix-are-able-to-logically-present-a-non-linear-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!