简体   繁体   English

List和Graph的数据结构有什么区别?

[英]What's the difference between the data structure List and Graph?

I know that singly linked lists are made of nodes where each node has a pointer to the next node (or null to end the list), but graphs also have nodes with data and pointers to the next.我知道单向链表由节点组成,其中每个节点都有一个指向下一个节点的指针(或 null 以结束列表),但图也有包含数据的节点和指向下一个节点的指针。

So what's the essential difference between the data structure Linked List and Graph?那么链表和图的数据结构有什么本质区别呢? And how about the List-based search and Graph-based search?那么基于列表的搜索和基于图的搜索呢?

It is not true, linked list also have data in it's nodes!(why do you want to have a list of nodes without any information?), In fact from mathematical view a linked list is some sort of graph .这不是真的,链表的节点中也有数据!(为什么你想要一个没有任何信息的节点列表?),实际上从数学角度来看,链表是某种图形

The main difference between graph in general and linked list is that a node in linked list could at most have two pointers (one to its next and one to its previous node) but a node in graph could have more than two pointers .一般图和链表之间的主要区别在于,链表中的节点最多可以有两个指针(一个指向其下一个节点,一个指向其前一个节点),但图中的一个节点可以两个以上的指针

Linked list is data structure in computer science and graph is math abstraction.链表是计算机科学中的数据结构,图是数学抽象。 Linked list is one of possible implementations of graph.链表是图的可能实现之一。 You can always implement graph in a different way.您始终可以以不同的方式实现图形。 For example graph with n vertices can be implemented as an array[n][n] where if array[i][j] is true then there is an edge from vertex i to vertex j.例如,具有 n 个顶点的图可以实现为 array[n][n],其中如果 array[i][j] 为真,那么从顶点 i 到顶点 j 有一条边。
There are different implementations of linked list too.链表也有不同的实现。 You can keep link to previous and next node, or just to one of them.您可以保持指向上一个和下一个节点的链接,或者只链接到其中一个节点。 But it will be a node with link to another node, because it's definition of linked list.但它将是一个链接到另一个节点的节点,因为它是链表的定义。 Definition of graph doesn't say anything about how to keep it in computer program.图的定义并没有说明如何将其保存在计算机程序中。

Linked List and Graph has similarities but the linked list nodes are rigid.链表和图有相似之处,但链表节点是刚性的。 The nodes of linked list has predefined structure but nodes in graph do not have predefined structure, for examples one node of a graph can have any number of connection to the other node but the list node has predefined connections.链表的节点有预定义的结构,但图中的节点没有预定义的结构,例如图的一个节点可以与另一个节点有任意数量的连接,但列表节点有预定义的连接。 The list node can only connect to the same type of node but the graph node can be connected to different type of node as well.列表节点只能连接到相同类型的节点,但图节点也可以连接到不同类型的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM