Held Thursday, December 2, 1999
Overview
Today, we continue our consideration of the graph data structure
by visiting some common graph problems.
Notes
- For Friday, try to think of a faster way to do shortest path.
- Are there any new questions on exam 3?
- Some of you have asked what you have to turn in for the project.
- Your portion of the project, which has been tested with any other
components you use or are used by.
- A short (3 page) "reader's guide" for your code. This should be
sufficient for someone else to modify or maintain your code.
It should not be the Javadoc for your code.
- Each team member should turn in a one-page report on the experience.
What were good/bad/helpful/etc parts of doing this scale of project?
Contents
Summary
- Graphs and modeling
- Common graph problems
- The traveling salescritter problem
- Reachability
- We can phrase a number of modeling problems in terms of graphs.
- In the telephone system, find the least congested route between
two phones, given connections between switching stations.
- In a nonnegatively weighted (by congestion) undirected graph, find a
path from node A to node B with lowest maximum edge.
- On the Web, determine if there is a way to get to one page from
another, just by following normal links.
- In a directed graph, determine whether node B is reachable from
node A.
- While driving, find the shortest path from one city to another.
- In a weighted directed graph (or simply a directed graph) (or even an
undirected graph), find the
shortest path from node A to node B.
- Determine someone's ``Kevin Bacon Degree''
- In an undirected graph, find the shortest path from
from node A to node B.
- Actors are nodes.
- Movies are edges. A movie connects all pairs of actors that
appeared in the movie.
- As a traveling salesperson who needs to visit a number of cities,
find the shortest path that includes all the cities.
- In an undirected graph, find the shortest path that includes all nodes
(often called a tour).
- On the Internet, determine how many connections between
computers you can eliminate and still make sure that
every computer can reach every other computer.
- In a (possibly weighted) graph, find a minimum spanning tree.
A spanning three is a set of edges such that every node is reachable
from every other node, and the removal of any edge from the tree
eliminates the reachability property. A minimum spanning tree is the
smallest such tree.
- Determine an ordering of classes so that you always take
prerequisite courses first.
- Number the nodes in a directed acyclic graph in such a way
that if there
is a path from A to B, then the number assigned to A (the term in
which you take A) is smaller
than the number assigned to B.
- One advantage of modeling problems with graphs is that we can then
solve more general problems on the graphs an then use those solutions
to solve a wide variety of ``real-world'' questions.
- That is, we will develop a number of graph algorithms to
solve typical problems.
- What are some of the core graph problems? In no
particular order,
- Reachability. Can you get to B from A?
- Shortest path (min-cost path). Find the path from B to A with
the minimum cost (determined as some simple function of the edges
traversed in the path).
- Minimum spanning tree. Find the ``smallest'' subset of
the edges in which all the nodes are connected.
- Traveling salesman. Find the smallest cost path through all
the nodes.
- Visit all nodes. Traversal.
- Transitive closure. Determine all pairs of nodes that can reach
each other.
- Topological sort. Number the nodes in such a way that any node
has a smaller number than all of its successors.
- We'll consider most of these algorithms in the next few days.
- There are also many variations of each of these. For example,
some versions of traveling salesperson require a cycle (returning
to the start), rather than a path.
- Many of you seemed to have heard vague "rumors" about the
traveling salescritter problem (TSP), so we'll begin with
that problem.
- The problem is to find the shortest path through a graph
that visits every node in the graph.
- Just as a salescritter must visit every location in its teritory,
so must this algorithm visit every node.
- As you might guess, this problem is typically considered
for weighted graphs (sometimes directed, sometimes undirected).
- Is there a solution? Certainly.
List every path that visits all the cities
Find the shortest such path
- Is this a good algorithm? No. It is O(n!). How bad
is that?
- 10! = 3,628,800
- 20! = 2,432,902,008,176,640,000
- If we could check and compare the length of one trillion paths
each second, checking 20! paths would take us 2,432,902 seconds
- That's 40548 minutes
- That's 675 hours
- That's about one month
- Surpisingly, no significantly better algorithm is known. That is, all
known algorithms are O(n!). Some just have better constants.
- However, it turns out that if you're willing to accept approximate
answers (e.g., a path no worse than two times as long as the best path),
then there are much faster solutions.
Tuesday, 10 August 1999
- Created as a blank outline.
Wednesday, 1 December 1999
- Copied list of problems from previous outline.
- Added notes on reachability from
outline 51 of
CS152 99S
- Reformatted.
- Added notes on TSP.
Thursday, 2 December 1999
- Removed section on shortest path (moved to next outline).
Back to Introduction to Graphs.
On to Shortest Path.