如果我们不知道节点的位置,那么单链列表和双链列表是否都需要O(n)时间才能删除?
My understanding is that we need to traverse to node to know the previous pointer of the node and next pointer of node in singly linked list. The time complexity for singly linked list to delete is O(n) as a result.
For doubly linked list, since we know the previous and next pointers of the node we want to delete, the time complexity is O(1).
algorithm optimization computer-science time-complexity data-structures