graph - What are the disadvantages if I replace each linked list in adjacency-list with hash table?

后端 未结 3 399
说谎
说谎 2021-01-30 18:26

In CLRS excise 22.1-8 (I am self learning, not in any universities)

Suppose that instead of a linked list, each array entry Adj[u] is a hash table conta

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 18:54

    The answer to question 3 could be a binary search tree.

    In an adjacency matrix, each vertex is followed by an array of V elements. This O(V)-space cost leads to fast (O(1)-time) searching of edges.

    In an adjacency list, each vertex is followed by a list, which contains only the n adjacent vertices. This space-efficient way leads to slow searching (O(n)).

    A hash table is a compromise between the array and the list. It uses less space than V, but requires the handle of collisions in searching.

    A binary search tree is another compromise -- the space cost is minimum as that of lists, and the average time cost in searching is O(lg n).

提交回复
热议问题