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

后端 未结 10 1809
醉话见心
醉话见心 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 17:59

    Trees are obvious: they're recursive data structures consisting of nodes with children.

    Map (aka dictionary) are key/value pairs. Give a map a key and it will return the associated value.

    Maps can be implemented using trees, I hope you don't find that confusing.

    UPDATE: Confusing "graph" for "map" is very confusing.

    Graphs are more complex than trees. Trees imply recursive parent/child relationships. There are natural ways to traverse a tree: depth-first, breadth-first, level-order, etc.

    Graphs can have uni-directional or bi-directional paths between nodes, be cyclic or acyclic, etc. I would consider graphs to be more complex.

    I think a cursory search in any decent data structures text (e.g. "Algorithms Design Manual") would give more and better information than any number of SO answers. I would recommend that you not take the passive route and start doing some research for yourself.

提交回复
热议问题