VOOZH about

URL: https://www.geeksforgeeks.org/dsa/insert-a-node-at-front-beginning-of-a-linked-list/

⇱ Insert a Node at Front of a Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Insert a Node at Front of a Linked List

Last Updated : 21 Oct, 2025

Given a head of the linked list, Insert a new node at the beginning/start/front of the linked list.

Example:

Input: x = 1

👁 111


Output: 1 -> 2 -> 3 -> 4 -> 5
Explanation: We can see that 1 is inserted at the beginning of the linked list.

👁 222-


Input: x = 1

👁 333


Output: 1 -> 2 -> 10
Explanation: We can see that 1 is inserted at the beginning of the linked list.

👁 444


Approach:

To insert a new node at the front, we create a new node and point its next reference to the current head of the linked list. Then, we update the head to be this new node. This operation is efficient because it only requires adjusting a few pointers.

Algorithm:

  • Make the first node of Linked List linked to the new node
  • Remove the head from the original first node of Linked List
  • Make the new node as the Head of the Linked List.

Below is the implementation of the approach:


Output
1 -> 2 -> 3 -> 4 -> 5

Time Complexity: O(1), We have a pointer to the head and we can directly attach a node and update the head pointer. So, the Time complexity of inserting a node at the head position is O(1).
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: