Why deletion of elements of hash table using doubly-linked list is O(1)?

前端 未结 8 1329
野的像风
野的像风 2020-12-23 10:20

On CLRS\'s textbook \"Introduction to Algorithm\", there\'s such paragraph on pg. 258.

We can delete an element in O(1) time if the lists are doubly linked. (Note th

8条回答
  •  攒了一身酷
    2020-12-23 11:01

    In general you are correct - the algorithm you posted takes an element itself as input though and not just its key:

    Note that CHAINED-HASH-DELETE takes as input an element x and not its key k, so that we don't have to search for x first.

    You have the element x - since it is a double linked list you have pointers to predecessor and successor, so you can fix those elements in O(1) - with a single linked list only the successor would be available, so you would have to search for the predecessor in O(n).

提交回复
热议问题