Like this presentation? Why not share!

# Data structure computer graphs

## by Vichitra Kumar,Student At University Of Petroleum And Energy Studies on Apr 17, 2013

• 499 views

### Views

Total Views
499
Views on SlideShare
499
Embed Views
0

Likes
0
13
0

No embeds

### Categories

Uploaded via SlideShare as Microsoft PowerPoint

## Data structure computer graphsPresentation Transcript

• Graphs
• What is a graph?• A data structure that consists of a set of nodes(vertices) and a set of edges that relate the nodesto each other• The set of edges describes relationships among thevertices
• Formal definition of graphs• A graph G is defined as follows:G=(V,E)V(G): a finite, nonempty set of verticesE(G): a set of edges (pairs of vertices)
• Directed vs. undirected graphs• When the edges in a graph have nodirection, the graph is called undirected
• • When the edges in a graph have a direction,the graph is called directed (or digraph)Directed vs. undirected graphs(cont.)E(Graph2) = {(1,3) (3,1) (5,9) (9,11)(5,7)Warning: if the graph isdirected, the order of thevertices in each edge isimportant !!
• • Trees are special cases of graphs!!Trees vs graphs
• Graph terminology• Adjacent nodes: two nodes are adjacent ifthey are connected by an edge• Path: a sequence of vertices that connecttwo nodes in a graph• Complete graph: a graph in which everyvertex is directly connected to every othervertex5 is adjacent to 77 is adjacent from 5
• • What is the number of edges in a completedirected graph with N vertices?N * (N-1)Graph terminology (cont.)
• • What is the number of edges in a completeundirected graph with N vertices?N * (N-1) / 2Graph terminology (cont.)
• Graph terminology (cont.)• Multi-graph• Cycle• Loop
• • Weighted graph: a graph in which each edgecarries a valueGraph terminology (cont.)
• Graph implementation• Array-based implementation– A 1D array is used to represent the vertices– A 2D array (adjacency matrix) is used torepresent the edges