Abstract
■■■
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
I’ve “stolen” the subtitle for this chapter from Dudley Ernest Littlewood’s The Skeleton Key of Mathematics.
- 2.
If you’re not a gamer, feel free to imagine this as your office building, dream home, or whatever strikes your fancy.
- 3.
I’ll be using dicts with adjacency sets as the default representation in the following, although many of the algorithms will work nicely with other representations from Chapter 2 as well. Usually, rewriting an algorithm to use a different representation isn’t too hard either.
- 4.
This is the running time of all the traversal algorithms in this chapter, except (sometimes) IDDFS.
- 5.
Hey, even the story of Newton and the apple is apocryphal.
- 6.
Tracing your tour from a, you should end up with the node sequence a, b, c, d, e, f, g, h, d, c, i, j, i, k, i, c, b, l, b, a.
- 7.
This recursive version would be harder to use if you were actually faced with a real-life maze, of course.
- 8.
And just like that, a spelunker can turn troglodyte.
- 9.
People seem to end up walking in circles when wandering in the wild as well. And research by the U.S. Army suggests that people prefer going south, for some reason (as long as they have their bearings). Neither strategy is particularly helpful if you’re aiming for a complete traversal, of course.
- 10.
My translation.
- 11.
You can perform the same procedure even if your boots aren’t muddy. Just make sure to clearly mark entries and exits (say, with a piece of chalk). In this case, it’s important to make two marks when you come to an old intersection and immediately start backtracking.
- 12.
In fact, in some contexts, the term backtracking is used as a synonym for recursive traversal, or depth-first search.
- 13.
The dfs_topsort function can also be used to sort the nodes of a general graph by decreasing finish times, as needed when looking for strongly connected components, discussed later in this chapter.
- 14.
In other words, let’s think inductively.
- 15.
IDDFS isn’t completely equivalent to Ore’s method because it doesn’t mark edges as closed in the same way. Adding that kind of marking is certainly possible and would be a form of pruning, discussed later in this chapter.
- 16.
On the other hand, we’ll be jumping from node to node in a manner that could not possibly be implemented in a real-life maze.
- 17.
To have any memory savings, you’d have to remove the S set. Because you’d be traversing a tree, that wouldn’t cause any trouble (that is, traversal cycles).
- 18.
This might seem like cheating because I’m using topological sorting on a non-DAG. The idea is just to get the nodes sorted by decreasing finish time, though, and that’s exactly what dfs_topsort does—in linear time.
- 19.
Actually, walk will return a traversal tree for each strong component.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2014 Magnus Lie Hetland
About this chapter
Cite this chapter
Hetland, M.L. (2014). Traversal: The Skeleton Key of Algorithmics. In: Python Algorithms. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0055-1_5
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0055-1_5
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0056-8
Online ISBN: 978-1-4842-0055-1
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books