---
title: "Describe the process of reversing a linked list iteratively and recursively."  
description: "Describe the process of reversing a linked list iteratively and recursively."  
author: "Steilla Mitchel"  
published: 2023-08-06  
updated: 2023-08-07  
canonical: https://www.mindstick.com/forum/159492/describe-the-process-of-reversing-a-linked-list-iteratively-and-recursively  
category: "data structure"  
tags: ["data structure", "linked list"]  
reading_time: 2 minutes  

---

# Describe the process of reversing a linked list iteratively and recursively.

[Describe the process](https://www.mindstick.com/forum/160416/describe-the-process-of-obtaining-and-using-a-bearer-token-in-an-oauth-2-0-authorization-flow) of reversing a [linked](https://answers.mindstick.com/qa/104773/how-to-create-a-linked-list) list iteratively and recursively.

## Replies

### Reply by Aryan Kumar

Sure. Here are the steps on how to reverse a linked list iteratively and recursively:

## Iterative Method

1. Initialize three pointers: `prev`, `curr`, and `next`.
2. Set `prev` to `None` and `curr` to the head of the linked list.
3. While `curr` is not `None`:

   - Set `next` to `curr`'s next node.
   - Set `curr`'s next node to `prev`.
   - Set `prev` to `curr`.
   - Set `curr` to `next`.

4. The reversed linked list will be from `prev` to `curr`.

## Recursive Method

1. Define a recursive function `reverse(head)` that takes the head of the linked list as input.
2. If the head is `None`, then return `None`.
3. Otherwise, return the reversed linked list, which is the reversed linked list of the head's next node, with the head node at the end.

Here is an example of the recursive function in Python:

Python

```plaintext
def reverse(head):
    if head is None:
        return None

    prev = None
    curr = head
    next = curr.next

    while curr is not None:
        curr.next = prev
        prev = curr
        curr = next

    return prev
```

Both the iterative and recursive methods have a time complexity of O(n), where n is the number of nodes in the linked list. This is because both methods need to visit each node in the linked list to reverse it.

The iterative method has a space complexity of O(1), because it only uses three pointers. The recursive method has a space complexity of O(n), because it needs to store the reversed linked list on the stack.

The iterative method is generally more efficient than the recursive method, because it does not need to use the stack. However, the recursive method is easier to understand and implement.


---

Original Source: https://www.mindstick.com/forum/159492/describe-the-process-of-reversing-a-linked-list-iteratively-and-recursively

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
