1 / 59

Paths in a Graph : A Brief Tutorial

Paths in a Graph : A Brief Tutorial. Krishna.V.Palem Kenneth and Audrey Kennedy Professor of Computing Department of Computer Science, Rice University. Introduction. Many problems can be modeled using graphs with weights assigned to their edges: Airline flight times

nam
Download Presentation

Paths in a Graph : A Brief Tutorial

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Paths in a Graph : A Brief Tutorial Krishna.V.Palem Kenneth and Audrey Kennedy Professor of ComputingDepartment of Computer Science, Rice University

  2. Introduction • Many problems can be modeled using graphs with weights assigned to their edges: • Airline flight times • Telephone communication costs • Computer networks response times Tokyo Subway Map

  3. Weighted Graphs • In a weighted graph, each edge has an associated numerical value, called the weight of the edge • Edge weights may represent, distances, costs, etc. • Example: • In a flight route graph, the weight of an edge represents the distance in miles between the endpoint airports 849 PVD 1843 ORD 142 SFO 802 LGA 1205 1743 337 1387 HNL 2555 1099 1233 LAX 1120 DFW MIA

  4. Shortest Path Problem • Given a weighted graph and two vertices u and v, we want to find a path of minimum total weight between u and v. • Length of a path is the sum of the weights of its edges. • Example: • Shortest path between Providence and Honolulu • Applications • Internet packet routing • Flight reservations • Driving directions 849 PVD 1843 ORD 142 SFO 802 LGA 1205 1743 337 1387 HNL 2555 1099 1233 LAX 1120 DFW MIA

  5. Dijkstra’s Algorithm to compute the Shortest Path • G is a simple connected graph. • A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. • Each edge has an associated weight • It is a greedy algorithm • A greedy algorithm is any algorithm that follows the problem solving metaheuristic of making the locally optimal choice at each stage with the hope of finding the global optimum.

  6. The distance of a vertex v from a vertex s is the length of a shortest path between s and v Dijkstra’s algorithm computes the distances of all the vertices from a given start vertex s Assumptions: the graph is connected the edges are undirected the edge weights are nonnegative We grow a “cloud” of vertices, beginning with s and eventually covering all the vertices We store with each vertex v a label d(v) representing the distance of v from s in the subgraph consisting of the cloud and its adjacent vertices At each step We add to the cloud the vertex u outside the cloud with the smallest distance label, d(u) We update the labels of the vertices adjacent to u Dijkstra’s Algorithm

  7. Application of Dijkstra’s Algorithm • Find shortest path from s to t using Dijkstra’s algorithm 2 24 3 9 s 18 14 6 2 6 4 19 30 11 5 15 5 6 16 20 t 7 44

  8. Dijkstra's Shortest Path Algorithm S = { } P = { s, 2, 3, 4, 5, 6, 7, t }   2 24 3 0 9 s 18  14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label 

  9. Dijkstra's Shortest Path Algorithm S = { } P = { s, 2, 3, 4, 5, 6, 7, t } delmin   2 24 3 0 9 s 18  14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label 

  10. Dijkstra's Shortest Path Algorithm S = { s } P = { 2, 3, 4, 5, 6, 7, t } decrease key   9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label  15 X

  11. Dijkstra's Shortest Path Algorithm S = { s } P = { 2, 3, 4, 5, 6, 7, t } delmin   9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44  distance label  15 X

  12. Dijkstra's Shortest Path Algorithm S = { s, 2 } P = { 3, 4, 5, 6, 7, t }   9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  13. Dijkstra's Shortest Path Algorithm S = { s, 2 } P = { 3, 4, 5, 6, 7, t } decrease key  33 X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  14. Dijkstra's Shortest Path Algorithm S = { s, 2 } P = { 3, 4, 5, 6, 7, t }  33 X  9 X 2 24 3 0 9 delmin s 18  14 X 14 6 2 6  4  19 30 11 5 15 5 6 16 20 t 7 44   15 X

  15. Dijkstra's Shortest Path Algorithm S = { s, 2, 6 } P = { 3, 4, 5, 7, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  44 4  X 19 30 11 5 15 5 6 16 20 t 7 44   15 X

  16. Dijkstra's Shortest Path Algorithm S = { s, 2, 6 } P = { 3, 4, 5, 7, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  44 4  X 19 30 11 5 15 5 6 16 20 t 7 44  delmin  15 X

  17. Dijkstra's Shortest Path Algorithm S = { s, 2, 6, 7 } P = { 3, 4, 5, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  35 44 X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  59 X  15 X

  18. Dijkstra's Shortest Path Algorithm delmin S = { s, 2, 6, 7 } P = { 3, 4, 5, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  35 44 X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  59 X  15 X

  19. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 6, 7 } P = { 4, 5, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  35 34 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  51 59 X X  15 X

  20. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 6, 7 } P = { 4, 5, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  35 34 44 X X 4  X 19 30 11 5 15 5 6 16 delmin 20 t 7 44  51 59 X X  15 X

  21. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 5, 6, 7 } P = { 4, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  22. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 5, 6, 7 } P = { 4, t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 delmin 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  23. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7 } P = { t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  24. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7 } P = { t } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  delmin 50 51 59 X X X  15 X

  25. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7, t } P = { } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  26. Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7, t } P = { } 32  33 X X  9 X 2 24 3 0 9 s 18  14 X 14 6 2 6  45 35 34 X 44 X X 4  X 19 30 11 5 15 5 6 16 20 t 7 44  50 51 59 X X X  15 X

  27. In-Class Exercise • Find the shortest route to reach Honolulu (HNL) from Providence (PVD) • Use Dikjstra’s algorithm 849 PVD 1843 ORD 142 SFO 802 LGA 1205 1743 337 1387 HNL 2555 1099 1233 LAX 1120 DFW MIA

  28. Why It Doesn’t Work for Negative-Weight Edges • If a node with a negative incident edge were to be added late to the cloud, it could mess up distances for vertices already in the cloud. • Dijkstra’s algorithm is based on the greedy method. • It adds vertices by increasing distance. 0 A 4 8 6 7 5 4 7 1 B C D 0 -8 5 9 2 5 E F C’s true distance is 1, but it is already in the cloud with d(C)=5!

  29. Remarks on Dijkstra’s Shortest Path Algorithm • Dijkstra’s algorithm doesn’t account for graphs whose edges may have negative weights • Bellman-Ford’s algorithm accounts for negative weight paths • Dijkstra’s algorithm works for a single source and a single sink pair • Floyd’s algorithm solves for the shortest path among all pairs of vertices. • Dijkstra’s shortest path algorithm can be solved in polynomial time in graphs without negative-weight cycles • It takes O(E+VlogV) time

  30. Bellman-Ford algorithm • Bellman-Ford Algorithm takes O(E*V) time

  31. Example of Bellman-Ford Algorithm We fix the source node as A Courtesy: Eric Demaine, MIT

  32. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  33. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  34. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  35. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  36. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  37. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  38. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  39. Example of Bellman-Ford Algorithm Courtesy: Eric Demaine, MIT

  40. Tractability • Some problems are undecidable: no computer can solve them • E.g., Turing’s “Halting Problem” • Other problems are decidable, but intractable: • as they grow large, we are unable to solve them in reasonable time • What constitutes “reasonable time”? • Some problems are provably decidable in polynomial time on an ordinary computer • We say such problems belong to the set P • Technically, a computer with unlimited memory

  41. NP • Some problems are provably decidable in polynomial time on a nondeterministic computer • We say such problems belong to the set NP • Can think of a nondeterministic computer as a parallel machine that can freely spawn an infinite number of processes • P = set of problems that can be solved in polynomial time • NP = set of problems for which a solution can be verified in polynomial time • PNP • The big question: Does P = NP?

  42. NP-Completeness • How would you define NP-Complete? • They are the “hardest” problems in NP NP-Complete P NP

  43. NP-Completeness • The NP-Complete problems are an interesting class of problems whose status is unknown • No polynomial-time algorithm has been discovered for an NP-Complete problem • No superpolynomial lower bound has been proved for any NP-Complete problem, either • The two chief characteristics of NP-complete problems are : • NP-complete is a subset of NP • set of all decision problems whose solutions can be verified in polynomial time; • A problem s in NP is also in NP-complete if and only if every other problem in NP can be transformed into s in polynomial time • Unless there is a dramatic change in the current thinking, there is no “efficient time” algorithm which can solve NP-complete problems • A brute-force search is often required

  44. Longest Path Algorithm • The longest path problem is the problem of finding a simple path of maximum length in a given graph. • Unlike the shortest path problem, the longest path problem is NP-complete • The optimal solution cannot be found in polynomial time unless P = NP. • The NP-completeness of the decision problem can be shown using a reduction from the Hamiltonian path problem. • If a certain general graph has a Hamiltonian path, this Hamiltonian path is the longest path possible, as it traverses all possible vertices.

  45. Longest Path Algorithm • A Hamiltonian path (or traceable path) is a path in an undirected graph which visits each vertex exactly once. • A Hamiltonian cycle (or Hamiltonian circuit) is a cycle in an undirected graph which visits each vertex exactly once and also returns to the starting vertex. • Determining whether such paths and cycles exist in graphs is the Hamiltonian path problem which is NP-complete.

  46. Statistics Krishna.V.Palem Kenneth and Audrey Kennedy Professor of ComputingDepartment of Computer Science, Rice University

  47. Contents • History of Statistics • Basic terms involved in Statistics • Sampling • Examples & In-Class Exercise • Estimation theory

  48. History of Statistics

  49. Contents • History of Statistics • Basic terms involved in Statistics • Sampling • Examples & In-Class Exercise • Estimation theory

  50. Basic Terms Involved in Statistics • To understand sampling, you need to first understand a few basic definitions. • The total set of observations that can be made is called the population. • A sample is a collection of observations made • It is usually a much smaller subset of the population • A parameter is a measurable characteristic of a population, such as a mean or standard deviation. • A statistic is a measurable characteristic of a sample, such as a mean or standard deviation.

More Related