Graphs in c language
Upcoming SlideShare
Loading in...5
×
 

Graphs in c language

on

  • 4,335 views

For PG students

For PG students

Statistics

Views

Total Views
4,335
Views on SlideShare
4,335
Embed Views
0

Actions

Likes
0
Downloads
67
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Graphs in c language Graphs in c language Presentation Transcript

    • Graphs in ‘C’ Language By Dr. C. Saritha Lecturer in ElectronicsSSBN Degree College, Anantapur
    • 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.
    • 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.
    • Types of data structure Data Structures Linear Non-LinearArrays Linked lists Stack Queue Trees Graphs
    • 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.
    • 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
    • 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
    • Edges & Vertices• Each node in a graph is known as a vertex of the graph.• The Each edge of a graph contains two vertices.
    • Types of Graphs• The Graphs can be classified into two types. They are:Undirected graphsDirected graph
    • 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.
    • 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)}
    • Directed Graphs 1 2 3• Set of vertices={1,2,3}• Set of edges= {<1,2>, <2,1>, <2,3>, <3,2>}
    • 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.
    • 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).
    • 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
    • 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
    • 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.
    • 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.
    • 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
    • Continue…• Source: A node, which has no incoming edges, but 1 2 has outgoing edges, is called a source. 3 4
    • 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
    • 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.
    • Continue…• Loop: An edge will be called loop or self edge if it starts and 1 2 ends on the same node. 3 4
    • 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
    • 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