Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:08:54+00:00 2026-06-18T10:08:54+00:00

Explain how to implement doubly linked lists using only one pointer value np[x] per

  • 0

Explain how to implement doubly linked lists using only one pointer value np[x] per item instead of the usual two (next and prev). Assume that all pointer values can be interpreted as k-bit integers, and def ine np[x] to be np[x] = next[x] XOR prev[x], the k-bit “exclusive-or” ofnext[x] and prev[x]. (The value NIL is represented by 0.) Be sure to describe what information is needed to access the head of the list. Show how to implement the SEARCH, INSERT, and DELETE operations on such a list. Also show how to reverse such a list in O(1) time.

Source: CLRS 10.2-8 of Cormen Third Edition

PS: This is not a homework question. I am practicing/revising data structures.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:08:55+00:00Added an answer on June 18, 2026 at 10:08 am

    Refer the pointer as a ‘regular’ integer. So, you can do any integer operations on it, including xor.

    For each node, store xorValue = next ^ previous.

    Why is it helpful?

    If you are iterating from front to end – you know where previous is, and you have its value, so you can get next with next = xorValue ^ previous.

    Same idea applies when iterating from last to first: previous = xorValue ^ next.

    This is enough since you cannot reach any place in the linked list without iterating from last to first or first to last – so the value of previous OR next is known to you, and as we have seen – it is all you need in order to get the other one.

    Based on this you can create (c-like Pseudo code):

    struct Node { 
       void* data;
       int xorValue;
    }
    Node* next(Node* node, void* previous) { 
        return (Node*)(node->xorValue ^ (int)previous));
    }
    Node* previous(Node* node, void* next) { 
        return (Node*)(node->xorValue ^ (int)next));
    }
    

    For the head/last elements – regard the previous/next value (correspondingly) as simply NULL (0), and store the next element as it is. It works since next ^ 0 = next

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Can any one explain me how to implement SQL Dependency Caching in Asp.Net?
Can anyone explain how to implement one-to-one, one-to-many and many-to-many relationships while designing tables
I'm trying to implement image scaling in OpenGL using only glTexCoord2f() and glVertex2f() .
Can anybody explain in detail how to implement a left outer join in LINQ?
Can somebody explain how the timeline of Path is implemented? Using UITableviewcell? Specifically I
Someone explain why the next code returns a pointer inside ntdll.dll? GetProcAddress(LoadLibraryA(kernel32.dll), EncodePointer); GetProcAddress(LoadLibraryA(kernel32.dll),
Can anyone who is using GZip for HTML, JS, PHP and CSS explain how
Please explain me how can i implement log4j in older version of Virtual machine?
I was trying to explain to someone why database connections implement IDisposable, when I
I need to implement automatic analyzing of output of the MySQL EXPLAIN command, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.