GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Discussion #36 Spanning Trees
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
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.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Balanced Binary Search Trees height is O(log n), where n is the number of elements in the tree AVL (Adelson-Velsky and Landis) trees red-black trees get,
Graph Operations And Representation. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Graphs - according to the mathematicians An undirected graph is 2-tuple: G=(V,E) a set of vertices a set of edges Vertices = {A, B, C, D, E} Edges = {
GRAPH Learning Outcomes Students should be able to:
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
SPANNING TREES Lecture 21 CS2110 – Spring
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Can you connect the dots as shown without taking your pen off the page or drawing the same line twice.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
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.
CSC 172 DATA STRUCTURES. WORKSHOP LEADER INTEREST MEETING FRIDAY, APRIL 6 th 12:30pm 601 CSB Good grades in CSC171 & CSC172 Good people skills Favorable.
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Union Find ADT Data type for disjoint sets: makeSet(x): Given an element x create a singleton set that contains only this element. Return a locator/handle.
COSC 2007 Data Structures II Chapter 14 Graphs I.
1 Chapter 4 Minimum Spanning Trees Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
CMSC 341 Disjoint Sets. 2 Disjoint Set Definition Suppose we have N distinct items. We want to partition the items into a collection of sets such that:
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Graphs and Paths : Chapter 15 Saurav Karmakar
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
CSE 373, Copyright S. Tanimoto, 2001 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Trees.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Minimum Spanning Tree Chapter 13.6.
CSE 373, Copyright S. Tanimoto, 2001 Up-trees -
Introduction to Graphs
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Minimum-Cost Spanning Tree
CSE 373 Data Structures and Algorithms
Graph Operations And Representation
Minimum-Cost Spanning Tree
CSC 172 DATA STRUCTURES.
Graphs G = (V, E) V are the vertices; E are the edges.
Graphs G = (V,E) V is the vertex set.
GRAPHS.
Minimum-Cost Spanning Tree
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

GRAPHS CSC 172 SPRING 2002 LECTURE 25

Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional B NAP SOURCE: CISCO SYSTEMS

GRAPHS GRAPH G= (V,E) V: a set of verticies (nodes) E: a set of edges connecting verticies  V An edge is a pair of nodes Example: V = {a,b,c,d,e,f,g} E = {(a,b),(a,c),(a,d),(b,e),(c,d),(c,e),(d,e),(e,f)} a b d c e fg

GRAPHS Labels (weights) are also possible Example: V = {a,b,c,d,e,f,g} E = {(a,b,4),(a,c,1),(a,d,2), (b,e,3),(c,d,4),(c,e,6), (d,e,9),(e,f,7)} a b d c e fg

DIGRAPHS Implicit directions are also possible Directed edges are arcs Example: V = {a,b,c,d,e,f,g} E = {(a,b),(a,c),(a,d), (b,e),(c,d),(c,e), (d,e),(e,f),(f,e)} a b d c e fg

Sizes By convention n = number of nodes m = the larger of the number of nodes and edges/arcs Note : m>= n

Complete Graphs An undirected graph is complete if it has as many edges as possible. a n=1 m=0 ab n=2 m=1 ab a n=3 m=3 ab ab n=4 m=6 What is the general form? Basis is = 0 Every new node (nth) adds (n-1) new edges (n-1) to add the nth

In general

Paths In directed graphs, sequence of nodes with arcs from each node to the next. In an undirected graph: sequence of nodes with an edge between two consecutive nodes Length of path – number of edges/arcs If edges/arcs are labeled by numbers (weights) we can sum the labels along a path to get a distance.

Cycles Directed graph: path that begins and ends at the same node Simple cycle: no repeats except the ends The same cycle has many paths representing it, since the beginning/end point may be any node on the cycle Undirected graph Simple cycle = sequence of 3 or more nodes with the same beginning/end, but no other repetigions

Representations of Graphs Adjacency List Adjacency Matrices

Adjacency Lists An array or list of headers, one for each node Undirected: header points to a list of adjacent (shares and edge) nodes. Directed: header for node v points to a list of successors (nodes w with an arc v  w) Predecessor = inverse of successor Labels for nodes may be attached to headers Labels for arcs/edges are attached to the list cell Edges are represented twice

Graph a b c d a b d c

Adjacency Matrices Node names must be integers [0…MAX-1] M[k][j]= true iff there is an edge between nodes k and j (arc k  j for digraphs) Node labels in separate array Edge/arc labels can be values M[k][j] Needs a special label that says “no edge”

a b d c GRAPH

Connected Components

Connected components a b d c e fg A connected graph a b d c e fg An unconnected graph (2 components)

Why Connected Components? Silicon “chips” are built from millions of rectangles on multiple layers of silicon Certain layers connect electrically Nodes = rectangles CC = electrical elements all on one current Deducing electrical ements is essential for simulation (testing) of the design

Minimum-Weight Spanning Trees Attach a numerical label to the edges Find a set of edges of minimum total weight that connect (via some path) every connectable pair of nodes To represent Connected Components we can have a tree

a b d c e fg

a b d c e fg

a b d c e fg

Representing Connected Components Data Structure = tree, at each node Parent pointer Height of the subtree rooted at the node Methods = Merge/Find Find(v) finds the root of the tree of which graph node v is a member Merge(T1,T2) merges trees T1 & T2 by making the root of lesser height a child of the other

Connected Component Algorithm 1. Start with each graph node in a tree by itself 2. Look at the edges in some order If edge {u,v} has ends in different trees (use find(u) & find(v)) then merge the trees Once we have considered all edges, each remaining tree will be one CC

Run Time Analysis Every time a node finds itself on a tree of greater height due to a merge, the tree also has at least twice as many nodes as its former tree Tree paths never get longer than log 2 n If we consider each of m edges in O(log n) time we get O(m log n) Merging is O(1)

Proof S(h): A tree of height h, formed by the policy of merging lower into higher has at least 2 h nodes Basis: h = 0, (single node), 2 0 = 1 Induction: Suppose S(h) for some h >= 0

Consider a tree of height h+1 t2t2 t1t1 Each have height of At least h BTIH: T 1 & T 2 have at least 2 h nodes, each 2 h + 2 h = 2 h+1

Kruskal’s Algorithm An example of a “greedy” algorithm “do what seems best at the moment” Use the merge/find MWST algorithm on the edges in ascending order O(m log m) Since m <= n2, log m <= 2 log n, so O(m log n) time

Traveling Salesman Problem Find a simple cycle, visiting all nodes, of minimum weight Does “greedy” work?

Implementation Classes Network Undirected Network Undirected Tree Undirected Graph DiGraph Tree

Network Class Vertex Methods public boolean containsVertex (Vertex vert) public boolean addVertex (Vertex vert) public boolean removeVertex (Vertex vert)

Network Class Edge Methods public int getEdgeCount(); public double getEdgeWeight (Vertex v1, Vertex v2) public boolean containsEdge(Vertex v1, Vertex v2) public boolean addEdge(Vertex v1, Vertex v2, double weight) public boolean removeEdge(Vertex v1, Vertex v2)

General Network Class Methods public Network() public Network(int V) public Network(Network network) public boolean isEmpty() public int size() public Iterator iterator()