7.26. Programming Exercises - Problem Solving With Algorithms and Data Structures PDF
7.26. Programming Exercises - Problem Solving With Algorithms and Data Structures PDF
4. Using breadth f irst search w rite an algorithm that can determine the shortest path f rom
each vertex to every other vertex. This is called the all pairs shortest path problem.
5. Using breadth f irst search revise the maze program f rom the recursion chapter to f ind the
shortest path out of a maze.
6. Write a program to solve the f ollow ing problem: You have tw o jugs, a 4-gallon and a
3-gallon. Neither of the jugs has markings on them. There is a pump that can be used to f ill
the jugs w ith w ater. How can you get exactly tw o gallons of w ater in the 4 gallon jug?
7. Generalize the problem above so that the parameters to your solution include the sizes of each
jug and the f inal amount of w ater to be lef t in the larger jug.
8. Write a program that solves the f ollow ing problem: Three missionaries and three cannibals
come to a river and f ind a boat that holds tw o people. Everyone must get across the river
to continue on the journey. How ever, if the cannibals ever outnumber the missionaries on
either bank, the missionaries w ill be eaten. Find a series of crossings that w ill get
everyone saf ely to the other side of the river.
1 of 1