Algorithms and data structures

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Chapter 8 Topics in Graph Theory
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
#1© K.Goczyła GRAPHS Definitions and data structuresDefinitions and data structures Traversing graphsTraversing graphs Searching for paths in graphsSearching.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPH Learning Outcomes Students should be able to:
Data Structures Using C++ 2E
IS 2610: Data Structures Graph April 5, 2004.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
SPANNING TREES Lecture 21 CS2110 – Spring
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Graphs Rosen, Chapter 8. Isomorphism (Rosen 560 to 563) Are two graphs G1 and G2 of equal form? That is, could I rename the vertices of G1 such that the.
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Data Structures & Algorithms Graphs
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Graphs Upon completion you will be able to:
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Leda Demos By: Kelley Louie Credits: definitions from Algorithms Lectures and Discrete Mathematics with Algorithms by Albertson and Hutchinson graphics.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Graph Search Applications, Minimum Spanning Tree
Graphs Chapter 20.
Basic Concepts Graphs For more notes and topics visit:
Spanning Trees Lecture 21 CS2110 – Fall 2016.
Shortest Path Problems
CS120 Graphs.
Comp 245 Data Structures Graphs.
Refresh and Get Ready for More
Graph Algorithm.
Minimum-Cost Spanning Tree
Graph Algorithm.
Graphs Chapter 13.
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Graphs Chapter 11 Objectives Upon completion you will be able to:
Minimum-Cost Spanning Tree
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Minimum-Cost Spanning Tree
Chapter 11 Graphs.
Shortest Path Problems
Minimum Spanning Tree Algorithms
Weighted Graphs & Shortest Paths
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
GRAPHS.
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Algorithms and data structures Graph representation Selected problems

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

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

Graph representation Incidence matrix Incidence lists m p m n o p n 1 1 o Incidence lists m n o p p n m o p p n m n o

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

Connected graph, connected component DFS

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

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.

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

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) }

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

Euler’s Cycle - Fleury’s alg. Start from a 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

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

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

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

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. 1 2 2 3 1

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. ?

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