SlideShare ist ein Scribd-Unternehmen logo
1 von 5
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

Weitere ähnliche Inhalte

Was ist angesagt?

Graph (Data structure)
Graph (Data structure) Graph (Data structure)
Graph (Data structure) shamiur rahman
 
Analytical geometry
Analytical geometryAnalytical geometry
Analytical geometrySiyavula
 
Graphing inequalities in two variables
Graphing inequalities in two variablesGraphing inequalities in two variables
Graphing inequalities in two variablesJessica Garcia
 
5.1 Finding Slope
5.1 Finding Slope5.1 Finding Slope
5.1 Finding Slopeguest7985b1
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c languageSARITHA REDDY
 
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.
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - GraphMadhu Bala
 
Math real life examples
Math real life examplesMath real life examples
Math real life examplesstudent
 
Graphing Linear Inequalities
Graphing Linear InequalitiesGraphing Linear Inequalities
Graphing Linear Inequalitiesinderjyot
 
Sequences & series
Sequences & seriesSequences & series
Sequences & seriesThabani Masoka
 

Was ist angesagt? (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]
 

Ähnlich wie Graph theory

Ähnlich wie 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
 

Mehr von 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 warKliment 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 societiesKliment Serafimov
 

Mehr von 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