GeeksforGeeks » Miscellaneous

Time complexity

(3 posts)
  1. raj
    Member
    Posted 1 year ago #

    What is the complexity of insertion and deletion of the following

    1) Queue
    2)Linked list
    3)Queue implemented using linked list

  2. geek4u
    Member
    Posted 1 year ago #

    For Linked List, if we always add a node to the front (or head) and also remove from the front (LIFO), then complexity is O(1) for both insert and delete. We just have to just change few links here and there, we don't need to traverse the complete list.

    For queue implementation using Array, both insert and delete can be done in O(1)

    For queue implementation using linked list, both operations can be done in O(1) . The only point is we have to keep track of both first node and last node in linked list.

    http://www.cs.princeton.edu/introcs/43stack/

  3. anant
    guest
    Posted 9 months ago #

    student


Reply

You must log in to post.

RSS feed for this topic