Upcoming SlideShare
×

# Data structure computer graphs

2,761 views

Published on

Published in: Technology
3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
2,761
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
193
0
Likes
3
Embeds 0
No embeds

No notes for slide

### Data structure computer graphs

1. 1. Graphs
2. 2. 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
3. 3. 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)
4. 4. Directed vs. undirected graphs• When the edges in a graph have nodirection, the graph is called undirected
5. 5. • 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 !!
6. 6. • Trees are special cases of graphs!!Trees vs graphs
7. 7. 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
8. 8. • What is the number of edges in a completedirected graph with N vertices?N * (N-1)Graph terminology (cont.)
9. 9. • What is the number of edges in a completeundirected graph with N vertices?N * (N-1) / 2Graph terminology (cont.)
10. 10. Graph terminology (cont.)• Multi-graph• Cycle• Loop
11. 11. • Weighted graph: a graph in which each edgecarries a valueGraph terminology (cont.)
12. 12. Graph implementation• Array-based implementation– A 1D array is used to represent the vertices– A 2D array (adjacency matrix) is used torepresent the edges