# Traveling Salesman Problem 1.

A salesman wishes to start at one city, visit a number of other cities, and end up back where he started. The cost of travel between each pair of cities is given, and the task is to find the cheapest route which visits all cities. 2. The brute force approach to solving this problem requires checking 1×2×3×4×...×(n - 1) routes, where n is the number of cities. o Actually, this number could be cut in half by observing that each route has the same length as its reverse, so we would need to check only one direction around each route. o The quantity 1×2×3×4×...×n is called "n factorial," and are denoted n! o Question 1: Is it true that 6!×7! = 10!? o The factorial numbers grow very fast. 1! = 1, 2! = 2, 5! = 120, 10! = 3628800, 20! = 2432902008176640000. This is why the brute force approach is completely hopeless for more than 20 cities. o Question 2: What is the number of routes that would need to be checked by brute force on a map with 13 cities? 3. So we have some heuristic algorithms for solving this problem. These heuristic methods run very fast (by computer...) on even several million cities, but they are not guaranteed to give the optimal solution o The "nearest neighbor" algorithm has you start at some city, and then at each step go to the nearest city which has not yet been selected. When all cities have been visited, return home. o The "repeated nearest neighbor" algorithm has you run the nearest neighbor algorithm from each possible starting point and then selecting the cheapest one you find o The "cheapest link" algorithm has you select at each step the cheapest edge (connection) available, subject to the conditions of not creating a vertex with 3 edges coming out of it, and not creating a premature cycle (that is, a cycle which does not contain all the cities that need to be visited). o Question 3: Run the nearest neighbor algorithm on the graph shown to the right, starting at vertex A o Question 4: Run the cheapest link algorithm on the graph shown to the right. o Question 5: Can you find a shorter path than either of these two algorithms give?

so I won't be testing you on anything from item 2. here. 3.  So one typically rephrases the Traveling Salesman Problem in the form: "Does this graph have a circuit of length less than 100? o It is possible to quickly verify a given solution o Any solution to the problem yields a quick solution to all problems which have solutions that can be quickly verified o We didn't talk about any of this in class. so that vertices which are connected by an edge get different colors? Question 7: What is the least number of colors required to color the vertices in the graph below. A problem is called NP-complete if: o It is a yes/no question.NP-Complete Problems 1.000. NP-Complete problems have the following two characteristics: o They are hard! All currently-known solutions to these problems are not a lot better than the brute force method of trying all possibilities o If you find a solution to one NP-complete problem. so that vertices which are connected by an edge get different colors? o o Question 8: What are two important ideas related to NP-complete problems? Question 9: What is the Traveling Salesman Problem? . can a thief fit \$1. then you have a solution to all other NP-complete problems as well. Question 6: What is the least number of colors required to color the vertices in the graph below. Other NP-Complete problems include: o Can the vertices of a given graph be colored with 3 colors so that vertices which are connected by an edge get different colors? o Given a knapsack which can hold 100 ounces of loot and a list of items with known weights and values.000 worth of loot into the knapsack? o Minesweeper 4. The traveling salesman problem is an example of an NP-complete problem 2.

5. o Question 10: Use the greedy algorithm described above to find a minimum weight spanning tree in the graph shown above. Also called "Finite State Machines. indicated in the diagram with an arrow into it coming from nowhere  And there can be any number of accept states. but usually the route it gives is not the shortest possible route. you want to find the cheapest set of edges which connects all the vertices (nodes. given a graph with costs on the edges of that graph. without worrying about the future consequences of that choice. Indicate the order in which your algorithm selected the edges to put into your minimum weight spanning tree.  A transition can loop back to the state it came from. The Nearest Neighbor and Cheapest Link algorithms given above are examples of greedy algorithms 2. o That is. Greedy algorithms tend to be fast 4." 2.  There must be exactly two transitions out of each state (including the start and accept states). A DFA consists of: o Some collection of states  A state is drawn as a circle in our diagrams  There must be one start state. But greedy algorithms do not always find the best solution to a given problem o For example. A greedy algorithm is one which makes all decisions based on what sems best at the time. 3.Greedy Algorithms 1. a transition for "0" and a transition for "1". indicated by a double-circle o Transitions between those states  A transition is drawn as an arrow from one state to another. Deterministic Finite Automata (DFA's) 1. also called a cheapest connecting network for that graph. . o The greedy algorithm for this problem says to select at each step the cheapest edge available such that you don't create a cycle within the edges you have chosen. sites) in that graph. One problem that greedy algorithms do solve optimally is the problem of finding a minimum weight spanning tree in a graph. the nearest neighbor algorithm selects at each step the cheapest available edge. and an arrow (or loop) may have more than one label on it.

o In this class. 10011. 111. o Also. 000. 1111. 011. the set of strings with an odd number of symbols.. That is. A string is a sequence of symbols. 1. 0011.3.}. 00011. 010. 00100.}.. computation on any string which starts with "00" will end in the lower-right state. o Computation stops when the end of the string is reached. 10. 010. The language of the DFA to the right is: {0. 00010. the set of all strings which do not contain "011" as a substring.. and the language of a DFA is the set of strings that the DFA accepts. 01011. 001. That is. 00001. that is. all of our symbols are the binary digits "0" and "1". 1101. 1. o The language of the DFA shown above is {11. This DFA accepts the language: {0. the set of strings which begin with "11". 111. 0000. and transitions according to the symbol that it reads. 1. 1010. in the DFA above. 110. 11. A language is a set of strings. 10. 1100. . o The machine begins computation in the start state o The machine then reads an input string one symbol at a time. 010. 101. . 00011. 101. 11011.com/people/nerp/automata/dfa1. That is. Otherwise the string is considered rejected.}. 1110. then the string is considered accepted by the machine. If the DFA is in an accept state at that point. These are "machines" which process an input string and move from state to state as they process the string. That is. the set of all strings which have no two consecutive symbols the same This DFA.... 101. 100. taken from the website: http://www. the set of all strings which end in "011". 11000. . 001. 00. 00000. This DFA accepts the language: {0. Some more examples: he language of the DFA to the right is: {011. 6.. 4...gif accepts all strings which contain an even number of 0s and an even number of 1s. .}.netaxs. .. 0101. 5. 000. 01. 0001. 111. 110. 110. . 1011. 100. 01.}.

such as {01. 111. 11.. This problem is called the "Halting problem. 5. we can prove that there are some tasks which a Turing machine cannot perform o Such as recognizing whether the program on its tape would ever print an "x" o Such as recognizing whether the program on its tape has an infinite loop or not." 4. As such. and onto which it can write 2. 011. Question 15: What is the Halting problem 6. .. A Turing machine is a simple model of computation. Question 16: Is it possible to write a computer program which reads another program as input and determines whether that program has an infinite loop or not? . 010. we can prove statements about what is or is not possible on a computer by proving that a Turing machine can or cannot do it. A Turing machine is a DFA with an attached tape from which it reads its input.} Turing Machines 1.Question 11: What is the language of the DFA shown to the right? Question 12: What is the language of the DFA shown to the right? o o Question 13: Construct a DFA which accepts a string if and only if it starts with "1" and ends with "00". 110. Turing machines are capable of implementing all algorithms which could be programmed into a computer 3. However. Question 14: Construct a DFA which accepts a string if and only if its second symbol is a "1".