1 / 18

Algorithms and data structures

This text provides an overview of graph representation and explores selected problems in the field, including directed graphs, multiple edges, loops, and weights. It discusses various algorithms and their applications in road building, minimal spanning trees, and shortest paths. The text also considers graph coloring and its applications in various domains.

mwannamaker
Télécharger la présentation

Algorithms and data structures

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. Algorithmsand data structures Graph representation Selected problems

  2. Graph 11 Directed Multiple edges 10 11 Loops 7 Weights Simple In more formal way: graph is an ordered pairG = (V, E) comprising a setV of vertices, nodes or points together with a set E of edges, arcs or lines, which are 2-element subsets of V

  3. Graph representation 1 0 0 A 1 1 B 1 C D A B C D A B D A B C D Adjacency matrix C Adjacency lists B A C D B D B C • If matrix is symetrical (graph is undirected), we can store only a half of matrix.

  4. Graph representation 0 1 0 1 m 1 0 1 1 n 0 1 0 1 o 1 1 1 0 p m n o p m p m n o p Incidence matrix n o Incidence lists n p m o p p n m n o

  5. Weights representation 0 0 0 0 A 2 0 0 0 B 0 3 0 2 C 0 7 5 0 D A B C D A 2 7 B D A B C D Adjacency matrix 3 5 C 2 Adjacency lists A,2 D,2 B,3 C,5 B,7

  6. Connected graph, connected component DFS

  7. Minimal Spanning Tree 2 4 2 3 1 8 5 6 2 3 4 6 Application:road building

  8. Minimal Spanning Tree Kruskal’s algorithm: Pick the edge with the smallest possible weights and avoid cycles. Pot. problem: eficient cicle detection. Prim-Dijkstra’s algorithm: CurrentTree = edges with the smallest weight CurrentEdge = Pick the smallest edge incident with CurrentTree Add CurrentEdge to CurrentTree. Pot. problem: disconnected graph.

  9. Shortest path 2 4 3 3 1 9 7 6 7 3 4 3 Applications: - shortest (fastest) road; - the least expensive (optimal) technology process.

  10. Dijkstra’s Algorithm • A.: Weights are not less than 0 Starting vertex s: di = , Visited = s, ds = 0; For every vertex i adjacent to Visited di = e(s,i) Repeat until reach destination vertex (or there are unreached vertexes in general case): From V–Visited pick vertex j with smallest dj Visited = Visited + j For any neighbar i of j vertex from V–Visited update: di = min{ dj,di+e(j,i) }

  11. Euler’s Cycle, Path Road – (open or not), that conatains all the edges from graph G Application: Chinese Postman ProblemDrawing/cutting with plotter aid.

  12. Euler’s Cycle - Fleury’s alg. • Start froma vertex current, where deg(current) is odd (if such vertex exists) • while G contains any edge pick any edge d incident to current but avoid bridges • traverse the edge d and update current • remove d from G

  13. Euler’s Cycle – stack algorithm • A: G is an Euler’s graph • current = Pick any vertex from G • while G contains edges and stack is not empty • if there exist any edge d incident with current • push current to the stack • traverse edge d and update current • remove edge d from G • else • move current to the solution pop current from the stack

  14. Graph coloring vertices edges Colors are assigned while avoiding conflicts with neighbars Coloring

  15. Coloring • Some interesting applications could be pointed i.e. • Assigning frequencies • Scheduling of lessons • Codes ressist for trasmission errors • Placing elements on curcuit board • Many more or less sophisticated models are studied • In general finding the optimal solution is very time-consuming so not optimal (but fast) algorithms are used

  16. LF – heuristic (Largest First) • Pick an unpainted vertex with a max degree; • Assign minimal possible color. LF quality is linear i.e for any n there exist graph that will require n colors more than optimal solution. 2 1 2 3 1 1 2 2 1 2 1

  17. SL – heuristic (Smallest Last) • Pick a vertex with smallest degree in remaining subgraph • Push vertex to the stack • Remove vertex (and incident edges) from graph • Color vertexes from the stack. ?

  18. Similar problems could be diffienent • Euler cycle (visit all edges) is easy • Hamilton cycle (visit all vertices) is hard • Shortest path is easy • Longest path is hard

More Related