• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Graphs
 

Graphs

on

  • 2,220 views

 

Statistics

Views

Total Views
2,220
Views on SlideShare
2,213
Embed Views
7

Actions

Likes
2
Downloads
0
Comments
0

1 Embed 7

http://www.slideshare.net 7

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 Graphs Presentation Transcript

    • Graphs MADE BY Zulkifal Yousaf [email_address]
    • Graph
      • A data structure that consists of a set of nodes ( vertices ) and a set of edges that relate the nodes to each other
      • The set of edges describes relationships among the vertices
      • Node:
      • Vertex point junction
      • Edge:
      • Give path.
      • TYPES OF GRAPHS:
      • 1)Directed
      • 2)Undirected
    • Undirected graphs When the edges in a graph have no direction, the graph is called undirected
        • edges do not have a direction
          • (V1, V2) and (V2, V1) are the same edge
      • When the edges in a graph have a direction, the graph is called directed (or digraph )
      Directed graphs E(Graph2) = {(1,3) (3,1) (5,9) (9,11) (5,7)
        • edges have a direction
          • <V1, V2> and <V2, V1> are different edges
    • Graph implementation
      • Array-based implementation
        • A 1D array is used to represent the vertices
        • A 2D array (adjacency matrix) is used to represent the edges
    • Array-based implementation
      • Linked-list implementation
        • A 1D array is used to represent the vertices
        • A list is used for each vertex v which contains the vertices which are adjacent from v (adjacency list)
    • Linked-list implementation
      • Traversing a graph
      • Where to start?
      • Will all vertices be visited?
      • How to prevent multiple visits?
    • Graph searching
      • Depth-First-Search (DFS) or Breadth-First-Search (BFS)
    • depth first traversal
      • depthFirstTraversal (v)
      • visit v
      • mark v as visited
      • for each neighbor (u) of v
      • if not yet visited
      • depthFirstTraversal (u)
      • Set found to false
      • stack.Push(startVertex)
      • DO
      • stack.Pop(vertex)
      • IF vertex == endVertex
      • Set found to true
      • ELSE
      • Push all adjacent vertices onto stack
      • WHILE !stack.IsEmpty() AND !found
      •  
      • IF(!found)
      • Write &quot;Path does not exist&quot;
      Depth-First-Search (DFS)
    • Depth-First-Search (DFS)
      • What is the idea behind DFS?
        • Travel as far as you can down a path
      • DFS can be implemented efficiently using a stack
    • start end (initialization)
    •  
    •  
    • Breadth-First-Searching (BFS)
      • What is the idea behind BFS?
        • Look at all possible paths at the same depth before you go at a deeper level
    • breadth first traversal
      • Breadth First Traversal (v)
      • put v in Q
      • while Q not empty
      • remove w from Q
      • visit w
      • mark w as visited
      • for each neighbor (u) of w
      • if not yet visited
      • put u in Q
      • BFS can be implemented efficiently using a queue
        • Set found to false
        • queue.Enqueue(startVertex)
        • DO
        • queue.Dequeue(vertex)
        • IF vertex == endVertex
        • Set found to true
        • ELSE
        • Enqueue all adjacent vertices onto queue
        • WHILE !queue.IsEmpty() AND !found
      •  
      Breadth-First-Searching (BFS) IF(!found) Write &quot;Path does not exist&quot;  
    • start end (initialization)
    • next:
    •  
    • EXAMPLES OF GRAPHS IN OUR DAILY LIFE FACEBOOK ,TWITTER,OTHER SOCAIL NETWORKS
    • some problems that can be represented by a graph
      • computer networks
      • airline flights
      • road map
      • course prerequisite structure
      • tasks for completing a job
      • flow of control through a program
      • many more
    • Types of Graphs
      • SIMPLE GRAPH
      • At most one edge between any pair of nodes.
    • Notation of graphs
      • A graph G is defined as follows:
      • G=(V,E)
      • V(G): a finite, nonempty set of vertices
      • E(G): a set of edges (pairs of vertices)
    • Multigraph
      • Multiple edges between nodes are allowed
    • Pseudographs
      • Self loops are permitted.
      • Trees are special cases of graphs!!
      Trees vs graphs