Is there any way to find an element in an unsorted doubly linked list given an element and pointer from which we can navigate? (we can't use head/tail pointers since the list is infinite)


1 Answer 1


Infinite/unbounded in both directions? Zig-zag.

  • $\begingroup$ Would that work something like this? - steps in powers of 2 in alternating directions (2 steps left, 4 steps right,.....until we find the element)? $\endgroup$
    – Sridhar
    Sep 10, 2017 at 8:32
  • $\begingroup$ @Sridhar No, just keep two pointers, left and right and decrement left and increment right. $\endgroup$
    – Pål GD
    Sep 10, 2017 at 14:13
  • $\begingroup$ @PålGD that would work of course, but the question suggested "an element and pointer" in singular. $\endgroup$ Sep 10, 2017 at 15:16
  • $\begingroup$ @Sridhar indeed! $\endgroup$ Sep 10, 2017 at 15:16
  • $\begingroup$ Thanks for the idea. The complexity would be exponential right? $\endgroup$
    – Sridhar
    Sep 11, 2017 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.