Skip to content
Related Articles

Related Articles

Improve Article

Can we reverse a linked list in less than O(n)?

  • Difficulty Level : Easy
  • Last Updated : 09 Jul, 2021
Geek Week

It doesn’t look possible to reverse a simple singly linked list in less than O(n). A simple singly linked list can only be reversed in O(n) time using recursive and iterative methods. 

A memory-efficient doubly linked list with head and tail pointers can also be reversed in O(1) time by swapping head and tail pointers. 

A doubly linked list with head and tail pointers can also be reversed in O(1) time by swapping head and tail pointers, but we would have to traverse the list in forward direction using prev pointer and reverse direction using next pointer which may not be considered valid. 

This article is contributed by Abhishek. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up
Recommended Articles
Page :