Skip to content
Related Articles
Open in App
Not now

Related Articles

Data Structures | Linked List | Question 16

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?


Delete the first element


Insert a new element as a first element


Delete the last element of the list


Add a new element at the end of the list

Answer: (C)


a) Can be done in O(1) time by deleting memory and changing the first pointer. b) Can be done in O(1) time, see push() here c) Delete the last element requires pointer to previous of last, which can only be obtained by traversing the list. d) Can be done in O(1) by changing next of last and then last.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!