Abstract

We consider paths in the 2D square grid, composed of grid edges, given as a sequence of moves in the four cardinal compass directions, without U-turns, but possibly passing several times through the same vertex or the same edge (if the path is open, it cannot pass twice through its starting vertex). We propose an algorithm which reports a self-crossing if there is one, or otherwise draws the path without self-crossings. The algorithm follows the intuitive idea naturally applied by humans to draw a curve: at each vertex that has already been visited, it tries to insert two new segments in such a way that they do not cross the existing ones. If this is not possible, a self-crossing is reported. This procedure is supported by a data structure combining a doubly-linked circular list and a skip list. The time and space complexity is linear in the length of the path.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call