230
6.5
Which of the following graphs are also trees?
Answers:
A—Tree; B—Not a tree; C—Tree. The last example is
just a sideways tree. Trees are a subset of graphs. So
a tree is always
a graph, but a graph may or may not be a tree.
CHAPTER 7
7.1
In each of these graphs, what is the weight of the shortest path
from start to finish?
Answers:
A: A—8; B—60; C—Trick question. No
shortest path is
possible (negative-weight cycle).
answers to exercises
231
CHAPTER 8
8.1
You work for a furniture company, and
you have to ship furniture
all over the country. You need to pack your truck with boxes. All
the boxes are of different sizes, and you’re trying to maximize
the space you use in each truck. How
would you pick boxes to
maximize space? Come up with a greedy strategy. Will that give
you the optimal solution?
Answer:
A greedy strategy would be to pick the largest box that
will
fit in the remaining space, and repeat until you can’t pack any
more boxes. No, this won’t give you the optimal solution.
8.2
You’re going to Europe, and you have seven
days to see everything
you can. You assign a point value to each item (how much you
want to see it) and estimate how long it takes. How can you
maximize the point total (seeing all the
things you really want to
see) during your stay? Come up with a greedy strategy. Will that
give you the optimal solution?
Answer:
Keep picking the activity with the highest point value that
you can still do in the time you have left. Stop when you can’t do
anything else. No, this won’t give you the optimal solution.
For each of these algorithms, say whether it’s a greedy algorithm or not.
Dostları ilə paylaş: