CHAPTER 14
More Network Algorithms
Chapter 13 focused on network traversal algorithms, including algorithms that use breadth-first and depth-first traversals to find the shortest paths between nodes in the network. This chapter continues the discussion of network algorithms. The first algorithms, which perform topological sorting and cycle detection, are relatively simple. The algorithms described later in the chapter, such as graph coloring and maximal flow calculation, are a bit more complicated.
Topological Sorting
Suppose you want to perform a complicated job that involves many tasks, some of which must be performed before others. For example, suppose you want to remodel your kitchen. Before you can get started, you may need to obtain permits from your local government. Then you need to order new appliances. Before you can install the appliances, however, you need to make any necessary changes to the kitchen's wiring. That may require demolishing the walls, changing the wiring, and then rebuilding the walls. A complex project such as remodeling an entire house or commercial building might involve hundreds of steps with a complicated set of dependencies.
Table 14-1 shows some of the dependencies you might have while remodeling a kitchen.
TASK | PREREQUISITE |
Obtain permit | — |
Buy appliances | — |
Install appliances | Buy appliances |
Demolition | Obtain permit |
Wiring | Demolition |
Drywall | Wiring |
Plumbing | Demolition |
Initial ... |
Get Essential Algorithms: A Practical Approach to Computer Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.