0% found this document useful (0 votes)
241 views

7.26. Programming Exercises - Problem Solving With Algorithms and Data Structures PDF

This document contains 8 programming exercises involving problem solving with algorithms: 1) Modify depth first search to produce a topological sort; 2) Modify depth first search to produce strongly connected components; 3) Write the transpose method for the Graph class; 4) Use breadth first search to find the shortest path between all vertices; 5) Use breadth first search to find the shortest path out of a maze; 6) Write a program to solve the problem of filling jugs with specific capacities to a target amount of water; 7) Generalize the jug filling problem to variable jug sizes and target amounts; 8) Write a program to solve the missionaries-and-cannibals river crossing problem with limited boat capacity.

Uploaded by

Err33
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

7.26. Programming Exercises - Problem Solving With Algorithms and Data Structures PDF

This document contains 8 programming exercises involving problem solving with algorithms: 1) Modify depth first search to produce a topological sort; 2) Modify depth first search to produce strongly connected components; 3) Write the transpose method for the Graph class; 4) Use breadth first search to find the shortest path between all vertices; 5) Use breadth first search to find the shortest path out of a maze; 6) Write a program to solve the problem of filling jugs with specific capacities to a target amount of water; 7) Generalize the jug filling problem to variable jug sizes and target amounts; 8) Write a program to solve the missionaries-and-cannibals river crossing problem with limited boat capacity.

Uploaded by

Err33
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

7.26.

Programming Exercises Problem Solving with Algorithms


6/11/17,
an... 6:31 PM

7.26. Programming Exercises


1. Modif y the depth f irst search f unction to produce a topological sort.

2. Modif y the depth f irst search to produce strongly connected components.

3. Write the transpose method f or the Graph class.

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

You might also like