What's the difference between the data structure Tree and Graph?

后端 未结 10 1810
醉话见心
醉话见心 2021-01-29 17:35

Academically speaking, what\'s the essential difference between the data structure Tree and Graph? And how about the tree based search and Graph based search?

10条回答
  •  野的像风
    2021-01-29 18:18

    Instead of explaining I prefer to show it in pictures.

    A tree in real time

    A tree in real time

    A graph in real life use

    A real time graph

    Yes a map can be visualised as a graph data structure.

    Seeing them like this makes life easier. Trees are used at places where we know that each node has only one parent. But graphs can have multiple predecessors(term parent is generally not used for graphs).

    In real world, you can represent almost anything using graphs. I used a map, for example. If you consider each city as a node, it can be reached from multiple points. The points which lead to this node are called predecessors and the points which this node will lead to are called successors.

    electrical circuit diagram, the plan of a house, computer network or a river system are few more examples of graphs. Many real world examples can be considered as graphs.

    Technical diagram could be like this

    Tree :

    enter image description here

    Graph :

    enter image description here

    Make sure to refer to below links. Those will answer almost all your questions on trees and graphs.

    References :

    1. http://www.introprogramming.info/english-intro-csharp-book/read-online/chapter-17-trees-and-graphs/#_Toc362296541

    2. http://www.community-of-knowledge.de/beitrag/data-trees-as-a-means-of-presenting-complex-data-analysis/

    3. Wikipedia

提交回复
热议问题