Data Structures & AlgorithmsVery hardGATE CS · DSA
XOR linked list: each node stores link = address(prev) XOR address(next). Which statement is correct?
- A. It allows O(1) random access
- B. Deleting a node needs no knowledge of its neighbours
- C. It needs two pointer fields per node
- D. Given the addresses of two adjacent nodes you can move in either direction, but a single node pointer alone is not enough to traverse
Correct answer: D. Given the addresses of two adjacent nodes you can move in either direction, but a single node pointer alone is not enough to traverse
next = link XOR prev, so traversal needs the previous node's address as well. It saves one pointer per node compared with a doubly linked list but still gives only sequential access.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Evaluate the postfix expression 1 9 9 ÷ 4 − 7 + − (all divisions are exact). What is its value, and what is the maximum number of operands…
- Floyd's cycle detection on a list whose last node links back into the list. What does this print (meeting value, cycle-start value, cycle…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "abaabaaba" z…
- Kadane's algorithm is applied to an array whose elements are ALL negative, using the version cur = max(x, cur + x), best = max(best, cur)…
- Remove the n-th node from the END of a linked list in one pass, using a dummy node and a gap of n between two pointers. What is printed?…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "bbaaaabab" z…