Your SlideShare is downloading. ×
Graphs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Graphs

2,013
views

Published on

Published in: Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,013
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Graphs MADE BY Zulkifal Yousaf [email_address]
  • 2. 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
  • 3.
    • Node:
    • Vertex point junction
    • Edge:
    • Give path.
    • TYPES OF GRAPHS:
    • 1)Directed
    • 2)Undirected
  • 4. 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
  • 5.
    • 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
  • 6. 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
  • 7. Array-based implementation
  • 8.
    • 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)
  • 9. Linked-list implementation
  • 10.
    • Traversing a graph
    • Where to start?
    • Will all vertices be visited?
    • How to prevent multiple visits?
  • 11. Graph searching
    • Depth-First-Search (DFS) or Breadth-First-Search (BFS)
  • 12. depth first traversal
    • depthFirstTraversal (v)
    • visit v
    • mark v as visited
    • for each neighbor (u) of v
    • if not yet visited
    • depthFirstTraversal (u)
  • 13.
    • 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)
  • 14. 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
  • 15. start end (initialization)
  • 16.  
  • 17.  
  • 18. 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
  • 19. 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
  • 20.
    • 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;  
  • 21. start end (initialization)
  • 22. next:
  • 23.  
  • 24. EXAMPLES OF GRAPHS IN OUR DAILY LIFE FACEBOOK ,TWITTER,OTHER SOCAIL NETWORKS
  • 25. 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
  • 26. Types of Graphs
    • SIMPLE GRAPH
    • At most one edge between any pair of nodes.
  • 27. 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)
  • 28. Multigraph
    • Multiple edges between nodes are allowed
  • 29. Pseudographs
    • Self loops are permitted.
  • 30.
    • Trees are special cases of graphs!!
    Trees vs graphs