Jonathan
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
^ yeah, the actual insertion procedure if O(1) (just reroute some pointers).
However, if you want to insert a node into the middle of a linked list, you really got to start from the beginning traverse to the position where you want to insert the node and then do the actual insertion procedure. The traversing would then take O(n).
Insertion at the beginning is O(1) (no traversing necessary).
And, inserting at the end could take O(1) if you kept a reference to the tail of the list.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
oh and return false if execution goes outside of the while loop.
- Jonathan April 05, 2014