71 Views

Download Presentation
##### Midterm 3 Revision

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Lecture 27**Midterm 3 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University**Quotation**• "Computer science is no more about computers than astronomy is about telescopes." • E. W. Dijkstra**Edsger Dijkstra made many more contributions to computer**science than the algorithm that is named after him. He was Professor of Computer Sciences in the University of Texas**Map of fly times between various cities (in hours)**6 b a 2 c h 3 i 4 1 e 4 5 d 2 g f**A more complicated network**2 8 0 1 2 1 4 3 9 2 1 3 4 7**DAM representation**2 8 0 1 2 1 4 3 9 2 1 0 1 2 3 4 0 8 - 9 4 - 0 1 - - - 2 0 3 - - - 2 0 7 - - 1 - 0 3 7 4 0 1 2 3 4**Shortest path**• The shortest path between any two vertices is the one with the smallest sum of the weighted edges • Example: what is the shortest path between vertex 0 and vertex 1?**Shortest path problem**2 8 0 1 2 1 4 3 9 2 1 Although it might seem like the shortest path is the most direct route... 3 4 7**Shortest path problem**2 8 0 1 2 1 4 3 9 2 1 3 4 7**Shortest path problem**2 8 0 1 2 1 4 3 9 2 1 3 4 7**Shortest path problem**2 8 0 1 2 1 4 3 9 2 1 The shortest path is really quite convoluted at times. 3 4 7**Shortest path solution**• Attributed to Edsger Dijkstra • Solves the problem and also determines the shortest path between a given vertex and ALL other vertices! • It uses a set S of selected vertices and an array W of weights such that W[v] is the weight of the shortest path (so far) from vertex 0 to vertex v that passes through all of the vertices in S.**How it works**• If a vertex v is in S the shortest path from v0 to v involves only vertices in S • If v is not in S then v is the only vertex along the path that is not in S (in other words the path ends with an edge from some vertex in S to v. • Clear as mud?**Shortest path problem**2 8 0 1 2 1 4 3 9 2 1 3 4 7**Dynamic Programming**One technique that attempts to solve problems by dividing them into subproblems is called dynamic programming. It uses a “bottom-up” approach in that the subproblems are arranged and solved in a systematic fashion, which leads to a solution to the original problem. This bottom-up approach implementation is more efficient than a “top-down” counterpart mainly because duplicated computation of the same problems is eliminated. This technique is typically applied to solving optimization problems, although it is not limited to only optimization problems. Dynamic programming typically involves two steps: (1) develop a recursive strategy for solving the problem; and (2) develop a “bottom-up” implementation without recursion.