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?

website link

enter image description here

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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -