SlideShare a Scribd company logo
Introduction to Graph Theory

     Eulerian path Algorithm
Graph theory
• A graph is used in mathematics and computer science
  to represent pairwise relations between objects.
• It is represented as a collection of nodes and edges.
  The edges connect the nodes.
• Each node or/and edge can have certain values or
  names assigned to it.
• Two nodes are called neighbors if they are connected
  with an edge.
• Two edges are connected if they have a common node.
• simple graph:
Example of a graph:




In this example the nodes are the cities in Macedonia and the
edges are the roads between a pair of cities.
Definition of the Eulerian path
                 problem
• Urban definition:
    Given a drawing on a piece of paper, try to cross all the lines
     with a pen such that the pen doesn’t leave the paper and you
     mustn’t cross a line more than once.
• Professional definition:
    Given a graph G, find a sequence of connected edges S such
     that every edge of G is found in S.
• Try solving:
The Algorithm
•   Step 1: we first have to input the graph, we will call the graph G.
•   Step 2: next we have to check if G is valid. If G is not valid, no solution exists and stop the algorithm.
      – How to check if G is valid:
            • First we have to determine the number of neighboring nodes to every node of G, we will keep
                this numbers in the sequence X.
            • Than we count how many odd numbers are there are in X, and we will call this number N.
            • If N = 0 or N = 2 the graph is valid, else the graph is not valid.
•   Step 3: next we have to find a starting node, we will name this node W.
      – if N = 0 than set W to a random node
      – If N = 2 than set W to a node with an odd number of neighbors
•   Step 4: define a stack S and push W onto S, also define a sequence of nodes P, P will contain the eulerian
    path solution to G.
•   Step 5: while S is nonempty repeat the following steps:
      – if W has at least one neighbor
            • Set O to the nearest node to W
            • Disconnect O from W
            • Set W to O
            • Go to step 5
      – Else add W to P, set W to the top of S, Pop the first element from S
•   Step 5: print P and stop the algorithm.
                                                                                      e.g. graph

More Related Content

What's hot

Graph (Data structure)
Graph (Data structure) Graph (Data structure)
Graph (Data structure)
shamiur rahman
 
Analytical geometry
Analytical geometryAnalytical geometry
Analytical geometry
Siyavula
 
Graphing inequalities in two variables
Graphing inequalities in two variablesGraphing inequalities in two variables
Graphing inequalities in two variables
Jessica Garcia
 
5.1 Finding Slope
5.1 Finding Slope5.1 Finding Slope
5.1 Finding Slope
guest7985b1
 
Finding slope
Finding slopeFinding slope
Finding slope
kjmonopoly7311
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
SARITHA REDDY
 
Graph
GraphGraph
Graph
WinNie Sjr
 
Can you trust the internet? An introduction to graph theory, computational co...
Can you trust the internet? An introduction to graph theory, computational co...Can you trust the internet? An introduction to graph theory, computational co...
Can you trust the internet? An introduction to graph theory, computational co...
Denise Gosnell, Ph.D.
 
Graph theory
Graph theoryGraph theory
Graph theory
Shubham Jain
 
Graph
GraphGraph
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
hamza javed
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
Mandeep Singh
 
Per5 sequences
Per5 sequencesPer5 sequences
Per5 sequences
Evert Sandye Taasiringan
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
Madhu Bala
 
Math real life examples
Math real life examplesMath real life examples
Math real life examples
student
 
Discount
DiscountDiscount
Discount
peabody6
 
Graphing Linear Inequalities
Graphing Linear InequalitiesGraphing Linear Inequalities
Graphing Linear Inequalities
inderjyot
 
Sequences & series
Sequences & seriesSequences & series
Sequences & series
Thabani Masoka
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 

What's hot (19)

Graph (Data structure)
Graph (Data structure) Graph (Data structure)
Graph (Data structure)
 
Analytical geometry
Analytical geometryAnalytical geometry
Analytical geometry
 
Graphing inequalities in two variables
Graphing inequalities in two variablesGraphing inequalities in two variables
Graphing inequalities in two variables
 
5.1 Finding Slope
5.1 Finding Slope5.1 Finding Slope
5.1 Finding Slope
 
Finding slope
Finding slopeFinding slope
Finding slope
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
 
Graph
GraphGraph
Graph
 
Can you trust the internet? An introduction to graph theory, computational co...
Can you trust the internet? An introduction to graph theory, computational co...Can you trust the internet? An introduction to graph theory, computational co...
Can you trust the internet? An introduction to graph theory, computational co...
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graph
GraphGraph
Graph
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
 
Per5 sequences
Per5 sequencesPer5 sequences
Per5 sequences
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Math real life examples
Math real life examplesMath real life examples
Math real life examples
 
Discount
DiscountDiscount
Discount
 
Graphing Linear Inequalities
Graphing Linear InequalitiesGraphing Linear Inequalities
Graphing Linear Inequalities
 
Sequences & series
Sequences & seriesSequences & series
Sequences & series
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 

Similar to Graph theory

Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
Tribhuvan University
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Ds lec 5_chap4
Ds lec 5_chap4Ds lec 5_chap4
Ds lec 5_chap4
Self-Employed
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Pooja Bhojwani
 
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptx
zerihunnana
 
10.graph
10.graph10.graph
Geometry
GeometryGeometry
Graphs (Models & Terminology)
Graphs (Models & Terminology)Graphs (Models & Terminology)
Graphs (Models & Terminology)
zunaira saleem
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Mohanlal Sukhadia University (MLSU)
 
Graph ds
Graph dsGraph ds
Unit 2: All
Unit 2: AllUnit 2: All
Unit 2: All
Hector Zenil
 
graph theory
graph theory graph theory
graph theory
ganith2k13
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
bashirabdullah789
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar
 
14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath
SSE_AndyLi
 
Lecture 1--Graph Algorithms -- Basics.pptx
Lecture 1--Graph Algorithms -- Basics.pptxLecture 1--Graph Algorithms -- Basics.pptx
Lecture 1--Graph Algorithms -- Basics.pptx
ChandanGiri21
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
bhuvaneshwariA5
 
Insider mathematical
Insider   mathematicalInsider   mathematical
Insider mathematical
Aditi Saxena
 

Similar to Graph theory (20)

Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Ds lec 5_chap4
Ds lec 5_chap4Ds lec 5_chap4
Ds lec 5_chap4
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptx
 
10.graph
10.graph10.graph
10.graph
 
Geometry
GeometryGeometry
Geometry
 
Graphs (Models & Terminology)
Graphs (Models & Terminology)Graphs (Models & Terminology)
Graphs (Models & Terminology)
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Graph ds
Graph dsGraph ds
Graph ds
 
Unit 2: All
Unit 2: AllUnit 2: All
Unit 2: All
 
graph theory
graph theory graph theory
graph theory
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath14 chapter9 graph_algorithmstopologicalsort_shortestpath
14 chapter9 graph_algorithmstopologicalsort_shortestpath
 
Lecture 1--Graph Algorithms -- Basics.pptx
Lecture 1--Graph Algorithms -- Basics.pptxLecture 1--Graph Algorithms -- Basics.pptx
Lecture 1--Graph Algorithms -- Basics.pptx
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
 
Insider mathematical
Insider   mathematicalInsider   mathematical
Insider mathematical
 

More from Kliment Serafimov

Technology used in the Iran-Iraq war
Technology used in the Iran-Iraq warTechnology used in the Iran-Iraq war
Technology used in the Iran-Iraq war
Kliment Serafimov
 
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
Kliment Serafimov
 
Социјализација и развој на личноста
Социјализација и развој на личностаСоцијализација и развој на личноста
Социјализација и развој на личноста
Kliment Serafimov
 
Love and revenge in Emily Bronte's "Wuthering Heights"
Love and revenge in Emily Bronte's "Wuthering Heights"Love and revenge in Emily Bronte's "Wuthering Heights"
Love and revenge in Emily Bronte's "Wuthering Heights"
Kliment Serafimov
 
балада за непознатиот
балада за непознатиотбалада за непознатиот
балада за непознатиот
Kliment Serafimov
 
Voting should be compulsory in democratic societies
Voting should be compulsory in democratic societiesVoting should be compulsory in democratic societies
Voting should be compulsory in democratic societies
Kliment Serafimov
 
Extreme sporten
Extreme sportenExtreme sporten
Extreme sporten
Kliment Serafimov
 
Extreme sports
Extreme sportsExtreme sports
Extreme sports
Kliment Serafimov
 
Computers and the internet
Computers and the internetComputers and the internet
Computers and the internet
Kliment Serafimov
 
Computers and the internet
Computers and the internetComputers and the internet
Computers and the internet
Kliment Serafimov
 

More from Kliment Serafimov (10)

Technology used in the Iran-Iraq war
Technology used in the Iran-Iraq warTechnology used in the Iran-Iraq war
Technology used in the Iran-Iraq war
 
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
IB Physics HL Full lab report on research question: Galileo’s experiment: mea...
 
Социјализација и развој на личноста
Социјализација и развој на личностаСоцијализација и развој на личноста
Социјализација и развој на личноста
 
Love and revenge in Emily Bronte's "Wuthering Heights"
Love and revenge in Emily Bronte's "Wuthering Heights"Love and revenge in Emily Bronte's "Wuthering Heights"
Love and revenge in Emily Bronte's "Wuthering Heights"
 
балада за непознатиот
балада за непознатиотбалада за непознатиот
балада за непознатиот
 
Voting should be compulsory in democratic societies
Voting should be compulsory in democratic societiesVoting should be compulsory in democratic societies
Voting should be compulsory in democratic societies
 
Extreme sporten
Extreme sportenExtreme sporten
Extreme sporten
 
Extreme sports
Extreme sportsExtreme sports
Extreme sports
 
Computers and the internet
Computers and the internetComputers and the internet
Computers and the internet
 
Computers and the internet
Computers and the internetComputers and the internet
Computers and the internet
 

Graph theory

  • 1. Introduction to Graph Theory Eulerian path Algorithm
  • 2. Graph theory • A graph is used in mathematics and computer science to represent pairwise relations between objects. • It is represented as a collection of nodes and edges. The edges connect the nodes. • Each node or/and edge can have certain values or names assigned to it. • Two nodes are called neighbors if they are connected with an edge. • Two edges are connected if they have a common node. • simple graph:
  • 3. Example of a graph: In this example the nodes are the cities in Macedonia and the edges are the roads between a pair of cities.
  • 4. Definition of the Eulerian path problem • Urban definition:  Given a drawing on a piece of paper, try to cross all the lines with a pen such that the pen doesn’t leave the paper and you mustn’t cross a line more than once. • Professional definition:  Given a graph G, find a sequence of connected edges S such that every edge of G is found in S. • Try solving:
  • 5. The Algorithm • Step 1: we first have to input the graph, we will call the graph G. • Step 2: next we have to check if G is valid. If G is not valid, no solution exists and stop the algorithm. – How to check if G is valid: • First we have to determine the number of neighboring nodes to every node of G, we will keep this numbers in the sequence X. • Than we count how many odd numbers are there are in X, and we will call this number N. • If N = 0 or N = 2 the graph is valid, else the graph is not valid. • Step 3: next we have to find a starting node, we will name this node W. – if N = 0 than set W to a random node – If N = 2 than set W to a node with an odd number of neighbors • Step 4: define a stack S and push W onto S, also define a sequence of nodes P, P will contain the eulerian path solution to G. • Step 5: while S is nonempty repeat the following steps: – if W has at least one neighbor • Set O to the nearest node to W • Disconnect O from W • Set W to O • Go to step 5 – Else add W to P, set W to the top of S, Pop the first element from S • Step 5: print P and stop the algorithm. e.g. graph