热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

数据结构图和树的区别Inthistutorialyouwilllearnaboutthedifferencebetweentreeandgraph.在本教程中,您将了

数据结构图和树的区别

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

数据结构图和树的区别



推荐阅读
  • HashMap的规约JavaDocs中HashMap的spec是这么写的:Hashtablebased implementationoftheMapinterface.Thisim ... [详细]
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 4.3.2Tuple是否可以跨页面PostgreSQLusesafixedpagesize(commonly8kB),anddoesnotallowtuplestospanmult ... [详细]
  • 阿里Treebased Deep Match(TDM) 学习笔记及技术发展回顾
    本文介绍了阿里Treebased Deep Match(TDM)的学习笔记,同时回顾了工业界技术发展的几代演进。从基于统计的启发式规则方法到基于内积模型的向量检索方法,再到引入复杂深度学习模型的下一代匹配技术。文章详细解释了基于统计的启发式规则方法和基于内积模型的向量检索方法的原理和应用,并介绍了TDM的背景和优势。最后,文章提到了向量距离和基于向量聚类的索引结构对于加速匹配效率的作用。本文对于理解TDM的学习过程和了解匹配技术的发展具有重要意义。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 本文介绍了在MFC下利用C++和MFC的特性动态创建窗口的方法,包括继承现有的MFC类并加以改造、插入工具栏和状态栏对象的声明等。同时还提到了窗口销毁的处理方法。本文详细介绍了实现方法并给出了相关注意事项。 ... [详细]
  • Postgresql备份和恢复的方法及命令行操作步骤
    本文介绍了使用Postgresql进行备份和恢复的方法及命令行操作步骤。通过使用pg_dump命令进行备份,pg_restore命令进行恢复,并设置-h localhost选项,可以完成数据的备份和恢复操作。此外,本文还提供了参考链接以获取更多详细信息。 ... [详细]
  • Python中程序员的面试题有哪些
    小编给大家分享一下Python中程序员的面试题有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有 ... [详细]
  • PriorityQueue源码分析
     publicbooleanhasNext(){returncursor<size||(forgetMeNot!null&am ... [详细]
  • 数据结构与算法习题replacementselectionsort(置换选择排序)TimeLimit:1000msMemoryLimit:65536kBDescrip ... [详细]
author-avatar
vincent
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有