What are Graphs?

Vijay Krishnavanshi

16 August, 2015

 

Table of contents

  • The graph structure
  • Types of graphs and their representation
  • Problems of graph theory, Algorithms 
    (an example)
  • Applications of graph theory
  • Using Graph in a Problem

What is a graph


  ?

Flashback

  • Leonhard Euler - 1735
  • The Seven Bridges of Königsberg
  • Challenge - walk all 7 bridges without crossing a bridge twice
  • Negative resolution - that's when it all began
     

The Graph structure

  • Graph - ordered pair  G = (V,E)
     V - finite set of vertices (nodes)
     E - finite set of edges (links) between nodes
  • Captures pairwise relationship between objects
    ‣ Each edge is a pair (v,w), where v, w V
    Loops, parallel and adjacent edges

    ‣ Adjacent and isolated vertices

Types of Graphs

 

  • Directed - the edges are ordered pairs (v, w) != (w, v)
  • Undirected - the edges are unordered pairs (v, w) == (w, v)
  • Mixed - combination of both
  • Dense - number of edges is close to the maximum number
  • Sparse - only few edges
  • Cyclic - directed graph with at least one cycle
    ‣ cycle - path along the edges from a vertex to itself
  • Weighted 
  • and many more ...

 

Graph Representations

  • Depends on:
    ‣ the graph structure
     the manipulation algorithm
  • Two main ways
    Adjacency matrix - faster access, huge amounts of memory
    Adjacency list - smaller memory requirements, good for
    sparse graphs

    Best way of representation: a combination of both

Try this :

You have to take the input and represent them using adjacency matrix or any of the stated ways of representation.

Do not try generalizing at first.

Keep it simple.

  1. Get the Matrix declared.
  2. If you take (x , y) as an edge put matrix_name[x][y] = matrix_name[y][x] = 1;

This one seems easy!

Key :

  • If (x,y) is an edge going from x to y but its not necessary for edge to turn back.
  • Visualize using one way passages.
  • Ideas are welcome.

Graph Algorithms

 

  • Elementary: graph-searching algorithms
    Breadth-first search, Depth-first search
  • Single-Source shortest paths:
     Algorithms of Bellman-Ford and Dijkstra
  • All-Pairs shortest paths: 
    ‣ Floyd-Warshall
  • Minimum spanning trees:
    Algorithms of Kruskal and Prim
  • Maximum flow: 
    ‣ Ford-Fulkerson method

 

One
Two
Three

Breadth First Search

Lets Keep it simple when you follow your intuition what do you see when you are standing on a four way.

In Breadth First Search we consider all the possibilities.

Key:

Let me show you this :

Dissected View

Prim's algorithm

..demo

Applications of Graph Theory


  • Routing problems
     Computer games - shortest path between two points
     
    Eulerian Path (Circuit) - postman, visiting each street (edge)
    ‣ Hamiltonian Path (Circuit) - postman, visiting each house (node)
    ‣ 
    Map applications
  • Minimum-spanning tree
    Modeling network topologies
  • Maximum flow 
    Transportation networks - traffic problems
  • and many more ...

 

Problem Solving:

For a given list of adjacent vertices of a graph and a chosen vertex v write down in Breadth First Search (BFS) order all the vertices from the connected component of the graph containing v. Assume that the number of vertices of the graph is at most 1000.

Input
t [the number of graphs <= 100]
Graph:
n [1 <=  n  <= 1000 the number of graph vertices]
m[ 1 <=m<= n(n+1) the number of edges]

x     y  [ 1 <= x,y <=n the edges between vertices ]
Output:

Listed edges in BFS order with 1 as root.

Questions?

Made with Slides.com