100%(1)1 out of 1 people found this document helpful
This preview shows page 188 - 192 out of 300 pages.
It turns out that each De Bruijn sequence corresponds to an Eulerian path ina graph. The idea is to construct a graph where each node contains a string ofn-1 characters and each edge adds one character to the string. The followinggraph corresponds to the above scenario:0011011011000101An Eulerian path in this graph corresponds to a string that contains allstrings of lengthn. The string contains the characters of the starting node andall characters of the edges. The starting node hasn-1 characters and there arekncharacters in the edges, so the length of the string iskn+n-1.178
19.4Knight’s toursAknight’s touris a sequence of moves of a knight on ann×nchessboardfollowing the rules of chess such that the knight visits each square exactly once.A knight’s tour is called aclosedtour if the knight finally returns to the startingsquare and otherwise it is called anopentour.For example, here is an open knight’s tour on a 5×5 board:14111625121725103207241518132296218191423A knight’s tour corresponds to a Hamiltonian path in a graph whose nodesrepresent the squares of the board, and two nodes are connected with an edge ifa knight can move between the squares according to the rules of chess.A natural way to construct a knight’s tour is to use backtracking. The searchcan be made more efficient by usingheuristicsthat attempt to guide the knightso that a complete tour will be found quickly.Warnsdorf’s ruleWarnsdorf’s ruleis a simple and effective heuristic for finding a knight’s tour3.Using the rule, it is possible to efficiently construct a tour even on a large board.The idea is to always move the knight so that it ends up in a square where thenumber of possible moves is assmallas possible.For example, in the following situation, there are five possible squares towhich the knight can move (squaresa...e):12abecdIn this situation, Warnsdorf’s rule moves the knight to squarea, because afterthis choice, there is only a single possible move. The other choices would movethe knight to squares where there would be three moves available.3This heuristic was proposed in Warnsdorf’s book  in 1823. There are also polynomialalgorithms for finding knight’s tours , but they are more complicated.179
Chapter 20Flows and cutsIn this chapter, we focus on the following two problems:•Finding a maximum flow: What is the maximum amount of flow we cansend from a node to another node?•Finding a minimum cut: What is a minimum-weight set of edges thatseparates two nodes of the graph?The input for both these problems is a directed, weighted graph that containstwo special nodes: thesourceis a node with no incoming edges, and thesinkis anode with no outgoing edges.As an example, we will use the following graph where node 1 is the sourceand node 6 is the sink:12364556541238Maximum flowIn themaximum flowproblem, our task is to send as much flow as possiblefrom the source to the sink. The weight of each edge is a capacity that restrictsthe flow that can go through the edge. In each intermediate node, the incoming