1.
Graphs in āCā Language By Dr. C. Saritha Lecturer in ElectronicsSSBN Degree College, Anantapur
2.
Data Structureā¢ Data structure is a particular way of sorting and organizing data in a computer. So that it can be used efficiently.ā¢ Different kinds of data structures are suited to different kinds of applications.
3.
Types of Data Structureā¢ Linear Data Structure: A data structure is said to be linear data structure if its elements form a sequence. Ex: Array, Stack , Queue and linked list.ā¢ Non-Linear Data Structure: Elements in a non-linear data structure do not form a sequence. Ex: Tree and Graph.
4.
Types of data structure Data Structures Linear Non-LinearArrays Linked lists Stack Queue Trees Graphs
5.
Treesā¢ A tree is hierarchical collection of nodes. One of the nodes, known as the root, is at the top of the hierarchical.ā¢ Each node can have utmost one link coming into it.ā¢ The node where the link originates is called the parent node. The root node has no parent.
6.
Continueā¦ā¢ The links leaving a node (any number of links are allowed) point to child nodes. A B C D E F G H I J
7.
Graphsā¢ A graph is a set of nodes (also called vertices) and a set of arcs (also called edges). A sample graph is as fallows: A B C D E
8.
Edges & Verticesā¢ Each node in a graph is known as a vertex of the graph.ā¢ The Each edge of a graph contains two vertices.
9.
Types of Graphsā¢ The Graphs can be classified into two types. They are:ļ¼Undirected graphsļ¼Directed graph
10.
Continueā¦ļ¼Undirected graphs: In an undirected graph the order of pair is unimportant. Hence the pairs (v1,v2)and (v2,v1) represent same edge.ļ¼Directed graph: In this the order of the vertices representing an edge is important. This pair is represented as <v1,v2> where v1 is the tail and v2 is head of v2. Thus <v1,v2> and <v2,v1> represents different edges.
11.
Undirected graph 1 2 5 3 4ā¢ Set of vertices={1,2,3,4,5}ā¢ Set of edges= {(1,2),(1,3),(1,4),(2,3), (2,4),(2,5),(3,4),(4,5)}
12.
Directed Graphs 1 2 3ā¢ Set of vertices={1,2,3}ā¢ Set of edges= {<1,2>, <2,1>, <2,3>, <3,2>}
13.
Adjacent Vectors & Incident Edgesā¢ In an undirected graph if (v1,v2) is an edge in the set of edges, then the vertices v1 and v2 are said to be adjacent and the edge (v1,v2) is incident on vertices v1 and v2.ā¢ If <v1,v2> is a directed edge, then vertex v1 is said to be adjacent to v2 while v2 is adjacent from v1.ā¢ The edge <v1,v2> is incident to v1 and v2.
14.
Continueā¦ā¢ The vertex 2 in the shown undirected graph is adjacent to 1 2 vertices 1,3,4 and 5.The edges incident 5 on vertex 3 are (1,3),(2,3) and 3 4 (3,4).
15.
Continueā¦ā¢ In the shown directed graph the 1 edges incident to vertex 2 are 2 <1,2>,<2,1>,<2,3> and <3,2>. 3
16.
Terminology of Graphsā¢ Weighted graph: A graph is said to be weighted graph if itās edges have been 2 2 assigned some non- 1 negative value as 5 weight. A weighted 6 graph is known as network. 3 4 3
17.
Continueā¦ā¢ Degree: In an undirected graph, the number of edges 1 2 connected to a node is called the degree of that node. Where is in digraph, there 4 3 are two degrees for every node they are indegree and outdegree.
18.
Continueā¦ā¢ Indegree: The indegree of node is the number of edges 1 2 coming to that node.ā¢ Out degree: The out degree of node is 3 4 the number of edges going outside that node.
19.
Continueā¦ā¢ Isolated node: If any node has no edges connected with any other node then its degree will be zero (0) and it will be called as isolated node. A B C D E
20.
Continueā¦ā¢ Source: A node, which has no incoming edges, but 1 2 has outgoing edges, is called a source. 3 4
21.
Continueā¦ā¢ Connected graph: An undirected graph B A is said to be connected if there is a path from any C node of graph to D any other node. E
22.
Continueā¦ā¢ Complete graph: An undirected graph 1 will contain n(n-1)/2 1 edges is called a complete graph 2 2 where as in the case of digraph will contain n(n-1) 3 3 edges, where n is the total number of nodes in the graph.
23.
Continueā¦ā¢ Loop: An edge will be called loop or self edge if it starts and 1 2 ends on the same node. 3 4
24.
Breadth first searchā¢ The general idea behind a breadth first traversal A B C beginning at a starting node A is as D E following. We first examine the starting node A, and then its F G neighbors after that the neighbors of its neighbors. ā¢ A BDE CFG
25.
Depth first searchā¢ In Depth first search technique also we take T H A one node as starting node. Then go to the K Y N path which from starting node and visit all the nodes which are O in the path. When we reach at the last node U then we traverse another path starting THANK YOU from that node
Be the first to comment