GithubHelp home page GithubHelp logo

graphs's Introduction

Graphs

Table of Contents

Introduction

A graph is a non-linear data structure that consists of a set of non-empty Vertices with a set of Edges.Each edge joins two different Vertices.

Types Of Graphs

  1. Undirected Graph
  2. Directed Graph

Undirected Graph

If an edge between any two nodes is not directly oriented, then it is undirected graph

(A,B) & (B,A) represents the same edge

Directed Graph (or) Digraph

If an edge between any two nodes is *directly oriented, then it is directed graph

(A,B) Shows the edge between A and B

Here A is called the Tail node and B is called the Head node

Restriction On a Graph

  • A graph may not have an edge from a vertex V back to itself. If it has an eged to itself, then it is called Self edges.
  • A graph may not have multiple occurrence of the same edges (multigraph)

Terminologies in Graph

Path

A path is a sequence of distinct Vertices each adjacent ot the next.

Path from A to C is (A,B),(B,C)

Cycle

A cycle is a simple path in which first and last vertices are same.

ABCD is cyclic as it starts and ends with the same vertex

In a digraph. a cycle is referred as Directed Cycle.

Note : The maximum number of edges in a graph with n vertices is n(n+1)/2

Complete Graph

An n-vertex, undirected graph with exactly n(n+1)/2 edges is said to be a complete graph.

n=4, no of edges = 4(4+1)/2 = 6

Subgraph

A subgraph of G is a graph G' such that *V(G') is a subset of V(G)

Subgraphs of G

Connected Graph

Undirected

If there exists a path from any vertex to any other vertex, then that graph is called connected graph.

Directed

If for every pair of distinct vertices there is a directed path from every vertex to every other vertices, then that graph is called Strongly connected graph.

Strongly Connected Graph

If any vertex dosen't have a directed path to any other vertices, then the graph is called Weakly connected Graph.

Weakly Connected graph

Degree of a graph

Undirected Graph Degree

Undirected graph only have one degree, ie. the The number of edges connected directly to a node

The degree of A is 2

Directed Graph Degree

Directed Graphs have two types of degrees, namely

  • Indegree - The number of edges entering the node.
  • Outdegree - The number of edges leaving the node.

Node Indegree Outdegree
A 1 1
B 1 1

Source Vertex

A vertex whose indegree is zero is referred as source vertex.

Sink Vertex

A vertex whose outdegree is zero is referred as sink vertex.

Isolated Vertex

If a graph has onlu one vertex in it, it is a isolated graph vertex.

Weighted Graph

If every edge in the graph is assigned some weight (or) value, then the graph is called Weighted Graph

Weighted Graph

Pendant Vertex

A vertex whose indegree is 1 and outdegree is 0 is referred to as Pendant Vertex.

Representation of a Graph

Incidence Matrix

A graph containing m vertices and n edges can be represented by a matrix with m rows and n columns. The matrix is formed by storing 1 in the ith row and jth column corresponding to the matrix, if there exists a ith vertex connected to one end of the jth edge and a 0 if there is no ith vertex connected to any end of the jth edge of the graph, such a matrix is referred to as incidence matrix.


Consider the given weighted graph

incidence_matrix[i][j] = 1, if there is an edge
                         0, otherwise

The Incidence Matrix for this graph is given by:

E1 E2 E3
V1 1 0 0
V2 0 1 0
V3 0 0 1
V4 1 1 1

Adjacency Matrix

A graph containing n vertices can be represented by a matrix with n rows and n columns if there exists an edge between ith and jth vertex of the graph, then 1 is stored in the ith row and jth column of the matrix, otherwise 0 is stored.

The Adjacency matrix for the graph is given by:

A B C D
A 0 1 0 0
B 0 0 1 0
C 1 0 0 0
D 1 1 1 0

Adjacency List

A graph containing m vertices and n edges can be represented using a linked list is referred to as adjacency list.

Adjacency List for Undirected Graph

V1 V2

graphs's People

Contributors

greyhatguy007 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ap0007

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.