c++ - Time Complexity in singly link list -
i studying data-structure: singly link list.
the website says singly linked list has insertion , deletion time complexity of o(1)
. missing something?
i in c++, , have root pointer
. if want insert @ end, have travel way back, means o(n)
.
the explanation is, big o notation in linked table refers function implementation itself, not including list traversal find previous reference node in list.
if follow link wikipedia article of singly-linkedlist implementation becomes more clear:
function insertafter(node node, node newnode) function removeafter(node node)
the above function signatures take predecessor node argument (same other variants implicitly).
finding predecessor different operation , may o(n) or other time complexity.
Comments
Post a Comment