Chapter 1 Example Problem Types Old world puzzle

Chapter 1 Example Problem Types

Old world puzzle • A farmer finds himself on the west bank of a river with a wolf, a goat, and a head of cabbage. He needs to transport all three to the east side of the river in his boat. However, the boat has room for only the farmer himself and one other item. In his absence, the wolf would eat the goat, and the goat would eat the cabbage. • Work in teams to solve this problem.

Old world puzzle solution 1. Farmer takes Goat across (leaving Wolf and Cabbage behind) 2. Farmer returns alone 3. Farmer takes Wolf across 4. Farmer returns with Goat * We now have the Farmer, the Cabbage and the Goat on one side and the Wolf on the other side 5. Farmer takes Cabbage across 6. Farmer returns alone 7. Farmer takes Goat across DONE!

Class exercise • Describe the algorithm used by your favorite ATM machine in dispensing cash. • You may give your description in either English or pseudocode, whichever you find more convenient.

Bike Tour • Suppose you decide to ride a bicycle around Ireland. • The goal is to visit Belfast, Cork, Dublin, Galway, and Limerick. • You need to return to your first city of visit to complete the circuit. • What is the best itinerary? • How can you minimize the number of kilometers yet make sure you visit all the cities? CEP 1: Find the shortest Tour. B G D L C

Optimal Tour • If there are only 5 cities it’s not too hard to figure out the optimal tour. • The shortest path is most likely a “loop”. • Any path that crosses over itself will be longer than a path that travels in a big circle.

Traveling Salesman Problem (TSP) • Find an optimal path between n points. • Clay Mathematics Institute will give you $1, 000! if you find an efficient algorithm. This tour of 13, 500 US cities was generated by an advanced algorithm that used several “tricks” to limit the number of possible tours Required 5 “CPU-years”

Unbeatable tic-tac-toe 1. Win: If the player has two in a row, they can place a third to get three in a row. 2. Block: If the opponent has two in a row, the player must play the third themselves to block the opponent. 3. Fork: Create an opportunity where the player has two threats to win 4. Blocking an opponent’s fork 5. Center: A player marks the center. 6. Opposite corner: If the opponent is in the corner, the player plays the opposite corner. 7. Empty corner: The player plays in a corner square. 8. Empty side: The player plays in a middle square on any of the 4 sides.

Important Problem Types • • Sorting Searching String processing Graph problems Combinatorial problems Geometric problems Numerical problems
- Slides: 9