1 / 10

Graphs

Graphs. A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called edges or arcs. undirected graph. directed graph (digraph). v. u. v. u. e. e. w. w. e = (v, w). (v, w) = (w, v).

arne
Download Presentation

Graphs

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. Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called edges or arcs. undirected graph directed graph (digraph) v u v u e e w w e = (v, w) (v, w) = (w, v) v: origin of e w: destination of e

  2. Applications of Graphs Java has a sophisticated Map interface, which has an extensive collection of methods and “views”. Here we present a stripped-down version.

  3. Some Terminologies • The vertices are adjacent to one another and that the edge is incident to both vertices. • The degree of a vertex is the number of edges incident to it. • A path is a sequence of vertices such that each adjacent pair of vertices is connected by an edge. • A cycle is a path with at least one edge whose first and last vertices are the same. • The length of a path or a cycle is its number of edges it traverses. • The distance from one vertex to another is the length of the shortest path from one to the other.

  4. Some Terminologies • An undirected graph is connected if there is a path from every vertex to every other vertex in the graph. A graph that is not connected consists of a set of connected components, which are maximal connected subgraphs. • A directed graph is strongly connected if for every pair of nodes u and v there is a path from u to v and a path from v to u.

  5. A few common graphs problems

  6. Representing Graphs We need to represent the vertices and the edges of a graph so that for any given vertex we can easily identify its neighbors An adjacency matrix is a V-by-V array of boolean values. Each row and column represents a vertex of the graph. Set the value at row i, column j to true if (i, j) is an edge of the graph. If the graph is undirected, the adjacency matrix is symmetric: row i, column j has the same value as row j, column i. Space Requirement?

  7. Representing Graphs An adjacency list is actually a collection of lists. Each vertex v maintains a list of the edges directed out from v. Space Requirement?

  8. Representing Graphs An adjacency list is actually a collection of lists. Each vertex v maintains a list of the edges directed out from v. The standard list representations all work — arrays, linked lists, even binary search trees (because you can traverse one in linear time). The total memory used by all the lists is O(V + E).

  9. Adjacency Matrix vs. Adjacency List An adjacency list is more space- and time-efficient than an adjacency matrix for a sparse graph, but less efficient for a complete graph. A complete graph is a graph having every possible edge; that is, for every vertex u and every vertex v, (u, v) is an edge of the graph.

  10. Depth-First Search DFS starts at an arbitrary vertex and searches a graph as “deeply” as possible and as early as possible. For example, if your graph is an undirected tree rooted at the starting vertex, DFS performs a postorder tree traversal.

More Related