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

前端 未结 8 1330
野的像风
野的像风 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 10:47

    While going through the textbook, I also got confused on the same topic(whether "x" is a pointer to an element or the element itself) and then eventually landed upon this question. But after going through the above discussion and referring textbook again, I think in the book "x" is implicitly assumed to be a "node" and its possible attributes are "key", "next".

    Some lines form the textbook..

    1)CHAINED-HASH-INSERT(T,x) insert x at the head of list T[h(x.key)]

    2)If the lists were only singly linked, then to delete element x, we would first have to find x in the list T[h(x.key)] so that we could update the next attribute of x’s predecessor.

    Hence we can assume that the pointer to the element is given and I think Fezvez has given a good explanation for the asked question.

提交回复
热议问题