Comparing object graph representation to adjacency list and matrix representations

后端 未结 4 1127
清歌不尽
清歌不尽 2021-01-29 22:42

I\'m currently following Steve Yegge\'s advice on preparing for a technical programming interview: http://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html

In

4条回答
  •  误落风尘
    2021-01-29 23:07

    Another good resource: Khan Academy - "Representing Graphs"

    Besides adjacency list and adjacency matrix, they list "edge lists" as a 3rd type of graph representation. An edge list could be interpreted as a list of "edge objects" like those in Thomas's "objects and pointers" answer.

    Advantage: We can store more information about the edge (mentioned by Michal)

    Disadvantage: It's a very slow data structure to work with:

    • Lookup an edge: O(log e)
    • Remove an edge: O(e)
    • Find all nodes adjacent to a given node: O(e)
    • Determine whether there exists a path between two nodes: O(e^2)

    e = number of edges

提交回复
热议问题