August 23, 2025 |7.3K Views

Palindrome Linked Lists

Explore Courseexplore course icon
Description
Discussion

In this video, we will discuss three methods to check if a singly linked list is a palindrome. The first approach uses a stack, where we push each node’s data onto the stack and then compare the nodes with the popped elements in the second traversal. This method runs in O(n) time and uses O(n) space due to the stack. The second approach employs recursion to compare nodes from the left and right, moving start forward and recursively checking the rest. This also runs in O(n) time but uses O(n) space for the recursion stack.

The third approach is the most efficient, utilizing an iterative method with two pointers: slow and fast. The fast pointer moves twice as fast as the slow pointer, allowing the slow pointer to reach the middle of the list. We then reverse the second half of the list and compare it with the first half. This method runs in O(n) time and uses O(1) space, making it optimal. Watch the video to learn the details of each approach and see how they work to check if a linked list is a palindrome.

For more details, please go through - Palindrome Linked List