VOOZH about

URL: https://www.geeksforgeeks.org/dsa/recursive-approach-alternating-split-linked-list/

⇱ Recursive approach for alternating split of Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Recursive approach for alternating split of Linked List

Last Updated : 23 Jan, 2023

Given a linked list, split the linked list into two with alternate nodes.

Examples: 

Input : 1 2 3 4 5 6 7
Output : 1 3 5 7
 2 4 6

Input : 1 4 5 6
Output : 1 5
 4 6

We have discussed Iterative splitting of linked list.

The idea is to begin from two nodes first and second. Let us call these nodes as 'a' and 'b'. We recurs

Implementation:


Output: 
a : 1 3 5 7 
b : 2 4 6 

 

Time Complexity: O(N)
Auxiliary Space: O(N)

Comment
Article Tags: