Algorithms icon indicating copy to clipboard operation
Algorithms copied to clipboard

XOR Linked List

Open Abhinavcode13 opened this issue 1 year ago • 2 comments

The XOR Linked List is a variation of a linked list where each node stores the XOR (exclusive OR) of the addresses of its previous and next nodes. It is named after the XOR operation, which is used to calculate the next and previous node addresses efficiently.

In a traditional linked list, each node holds a reference or pointer to its next node, allowing traversal from one node to another. In an XOR Linked List, instead of storing separate pointers, each node stores the XOR of the addresses of its previous and next nodes.

Let's consider a simple example to understand how XOR Linked Lists work. Suppose we have three nodes A, B, and C. Node B is between nodes A and C. In a regular linked list, node B would store a pointer to both nodes A and C. In an XOR Linked List, however, node B stores the XOR of the addresses of A and C, obtained by performing the XOR operation on the addresses.

To traverse the XOR Linked List, we need to know the addresses of two consecutive nodes. Starting from the head of the list, we can calculate the address of the next node by performing the XOR operation on the address stored in the current node and the address of the previous node. By repeating this process, we can traverse the entire list.

Abhinavcode13 avatar Jun 14 '23 12:06 Abhinavcode13

@Kumar-laxmi please assign me this

Abhinavcode13 avatar Jun 15 '23 02:06 Abhinavcode13

Stale issue message

github-actions[bot] avatar May 14 '24 16:05 github-actions[bot]