数据结构图和树的区别_树和图数据结构之间的区别

数据结构图和树的区别

In this tutorial you will learn about the difference between tree and graph.

在本教程中,您将了解树和图之间的区别。

Both trees and graphs are two well known mostly used data structures in algorithms.

树和图都是算法中两个众所周知的最常用的数据结构。

Tree Data Structure

树数据结构

In Computer science, a tree is a widely used Abstract Data Structure (ADT). It can be defined recursively as a collection of nodes, where each node contains a value, starting with root node and list of references to other nodes (children), with the constraint, that no reference from it, is called leaf node.

在计算机科学中,树是被广泛使用的抽象数据结构(ADT)。 可以将其递归定义为节点的集合,其中每个节点都包含一个值,该值从根节点开始,到对其他节点(子级)的引用列表,但有一个约束,即没有来自该节点的引用称为叶节点。

Graph Data Structure

图形数据结构

In Computer science, graph also an abstract data structure (ADT), that is mean to implement undirected graph and directed graph concepts of mathematics especially the field of graph theory. Graph is a mathematical representation of a set of objects and relationships or links between objects. We represent objects as nodes or vertices in graph and relations between vertices as edges or arcs. So, we can define that graph is set of vertices V and set of edges E. These edges may be directed or undirected.

在计算机科学中,图形也是一种抽象数据结构(ADT),它旨在实现数学的无向图和有向图概念,尤其是图论领域。 图是一组对象以及对象之间的关系或链接的数学表示。 我们将对象表示为图中的节点或顶点,并将顶点之间的关系表示为边或弧。 因此,我们可以定义图是由顶点V和边E组成的。这些边可以是有向的也可以是无向的。

Now let’s see what are the differences between graph and tree in tabular form.

现在,让我们看看表格形式的图和树之间的区别是什么。

树和图之间的区别 (Difference between Tree and Graph)

TreesGraphs
1. A tree is a special kind of graph that there are never multiple paths exist. There is always one way to get from A to B.1. A graph is a system that has multiple ways to get from any point A to any other point B.
2. Tree must be connected.2. Graph may not be connected.
3. Since it connected we can reach from one particular node to all other nodes. This kind of searching is called traversal.3. Traversal always not applicable on graphs. Because graphs may not be connected.
4. Tree contains no loops, no circuits.4. Graph may contain self-loops, loops.
5. There must be a root node in tree.5. There is no such kind of root node in graphs
6. We do traversal on trees. That mean from a point we go to each and every node of tree.6. We do searching on graphs. That means starting from any node try to find a particular node which we need.
7. pre-order, in-order, post-order are some kind of traversals in trees.7. Breath first search, Depth first search, are some kind of searching algorithms in graphs.
8. Trees are directed acyclic graphs.8. Graphs are cyclic or acyclic.
9. Tree is a hierarchical model structure.9. Graph is network model.
10. All trees are graphs.10. But all graphs are not trees.
11. Based on different properties trees can be classified as Binary tree, Binary search tree, AVL trees, Heaps.11. We differ the graphs like directed graphs and undirected graphs.
12. If tree have “n” vertices then it must have exactly “n-1” edges only.12. In graphs number of edges doesn’t depend on the number of vertices.
13. Main use of trees is for sorting and traversing.13. Main use of graphs is coloring and job scheduling.
14. Less in complexity compared to graphs.14. High complexity than trees due to loops.
树木 图表
树是一种特殊的图,它永远不会有多个路径。 从A到B总是有一种方法。 图是一种具有多种方法来从任何点A到达任何其他点B的系统。
2.必须连接树。 2.可能未连接图形。
3.由于它已连接,所以我们可以从一个特定节点到达所有其他节点。 这种搜索称为遍历。 3.遍历始终不适用于图形。 因为图形可能未连接。
4.树不包含回路,电路。 4.图可能包含自循环,循环。
5.树中必须有一个根节点。 5.图中没有这种根节点
6.我们在树上遍历。 这意味着从某个角度出发,我们进入树的每个节点。 6.我们在图上进行搜索。 这意味着从任何节点开始尝试找到我们需要的特定节点。
7.前序,有序,后序是树中的某种遍历。 7. 呼吸优先搜索深度优先搜索是图形中的某种搜索算法。
8.树是有向无环图。 8.图是循环的或非循环的。
9.树是一个分层的模型结构。 9.图是网络模型。
10.所有树都是图。 10.但是所有图形都不是树。
11.根据不同的属性,树可以分为二叉树,二叉搜索树,AVL树,堆。 11.我们区别于有向图和无向图之类的图。
12.如果树具有“ n”个顶点,则它必须仅具有精确的“ n-1”条边。 12.在图中,边的数量不取决于顶点的数量。
13.树木的主要用途是进行分类和遍历。 13.图形的主要用途是着色和作业计划。
14.与图形相比,复杂度更低。 14.由于循环,比树要复杂。

(Example)

Tree:

树:

Tree Data Structure

Graph:

图形:

Graph Data Structure

Comment below if you have queries or found any information incorrect in above tutorial for difference between tree and graph data structure.

如果您有疑问或在以上教程中发现任何信息不正确,请在下面评论,以区别树和图数据结构。

翻译自: https://www.thecrazyprogrammer.com/2017/08/difference-between-tree-and-graph.html

数据结构图和树的区别

  • 14
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值