-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worst case Singly-Linked List Insertion/deletion is O(1) #73
Comments
If I understand correctly, the notion is that insertion or deletion of a node at index So, while it is true that, if you do not know the node at I was confused by this earlier and I do not believe it is ideal, but I am not sure how else it should be represented. Additionally, this appears to be a duplicate of #65 |
Came here to report the same mistake. More information over here http://stackoverflow.com/a/14048223/6630282 |
Actually, you can delete a node in a singly linked list in O(1), even if you only have a pointer to that node and not its predecessor. The cost is copying the node data and having a sentinel node at the end. Specifically, to delete node (In other news, you can do mark&sweep garbage collection in time proportional to live memory.) |
Shouldn't the worst case insertion/deletion time of a Singly-Linked List be O(n). Both would involve traversal of the entire linked list to find the last node.
The text was updated successfully, but these errors were encountered: