DOC PREVIEW
GSU CSC 2510 - ch06s2

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Graph AlgorithmsEuler PathSlide 3Euler Path AlgorithmSlide 5Euler Path Algorithm ExampleSlide 7Euler Path AnalysisHamiltonian Circuit ProblemGraph AlgorithmsMathematical Structures for Computer ScienceChapter 6Copyright © 2006 W.H. Freeman & Co. MSCS Slides Graph AlgorithmsSection 6.2 Euler Path and Hamiltonian Circuit 2Euler PathDEFINITION: EULER PATH An Euler path in a graph G is a path that uses each arc of G exactly once.We want to find if an Euler path exists in graph G.Whether an Euler path exists in a given graph hinges on the degrees of its nodes.A node is even if its degree is even and odd if its degree is odd.THEOREM ON ODD NODES IN A GRAPH The number of odd nodes in any graph is even.Section 6.2 Euler Path and Hamiltonian Circuit 3Euler PathTHEOREM ON EULER PATHSAn Euler path exists in a connected graph if and only if there are either no odd nodes or two odd nodes. For the case of no odd nodes, the path can begin at any node and will end there; for the case of two odd nodes, the path must begin at one odd node and end at the other.The theorem on Euler paths is actually an algorithm to determine if an Euler path exists on an arbitrary connected graph.We make the simplifying assumption that the graph has no loops. If G has loops, we remove them and call the graph H. If H has an Euler path, then so does G, and vice versa.Section 6.2 Euler Path and Hamiltonian Circuit 4Euler Path AlgorithmIn the Euler Path algorithm, the input is a connected graph represented by an n  n adjacency matrix A.The algorithm counts the number of nodes adjacent to each node and determines whether this is an odd or an even number.If there are too many odd numbers, an Euler path does not exist.The variable total keeps track of the number of odd nodes found in the graph.The degree of any particular node, degree, is found by adding the numbers in that node’s row of the adjacency matrix.The function odd results in a value “true” if and only if the argument is an odd integer.Section 6.2 Euler Path and Hamiltonian Circuit 5Euler Path AlgorithmALGORITHM EulerPathEulerPath (n  n matrix A)//Determines whether an Euler path exists in a connected graph with//no loops and adjacency matrix A total = 0 i = 1 while total  2 and i  n do degree = 0 for j = 1 to n do degree = degree + A[i, j ] //find degree of node i (*) end for if odd(degree) then total = total + 1 //another odd degree node found end if i = i + 1 end while if total > 2 then write (“No Euler path exists”) Else write (“Euler path exists”) end ifend EulerPathSection 6.2 Euler Path and Hamiltonian Circuit 6Euler Path Algorithm ExampleGiven the following adjacency matrix:When the algorithm first enters the while loop, total is 0 and i is 1, then degree is 0. Within the for loop, the values of row 1 of the adjacency matrix are added in turn to degree, resulting in a value for degree of 3.The odd function applied to degree returns the value “true,” so the value of total is increased from 0 to 1; one node of odd degree has been found.Section 6.2 Euler Path and Hamiltonian Circuit 7Euler Path Algorithm ExampleThen i is incremented to 2.Neither the bounds on total nor the bounds on the array size have been exceeded, so the while loop executes again for row 2.degree is found to be odd, so the value of total is changed to 2.When the while loop is executed for row 3 of the array, the value of degree is even (4), so total does not change, and the while loop is executed again with i = 4.Row 4 again produces an odd value for degree, so total is raised to 3.This terminates the while loop. There is no Euler path because the number of odd nodes exceeds 2.Section 6.2 Euler Path and Hamiltonian Circuit 8Euler Path AnalysisIn the worst case, the while loop in the algorithm is executed n times, once for each row.Within the while loop, the for loop is executed n times, once for each column.EulerPath is therefore an Θ(n2) algorithm in the worst case.Section 6.2 Euler Path and Hamiltonian Circuit 9Hamiltonian Circuit ProblemA Hamiltonian circuit is a cycle using every node of the graph.A Hamiltonian circuit requires that each and every node of the graph be visited once and only once (except for the start node, which is also the end node)There can be unused arcs but no arc can be used more than once.No efficient algorithm has ever been found to determine if a Hamiltonian circuit


View Full Document

GSU CSC 2510 - ch06s2

Documents in this Course
ch02s2

ch02s2

5 pages

ch04s2

ch04s2

8 pages

ch01s6

ch01s6

10 pages

ch01s1

ch01s1

21 pages

ch02s4

ch02s4

10 pages

ch08s2

ch08s2

21 pages

ch08s3

ch08s3

15 pages

ch07s3

ch07s3

21 pages

ch04s3

ch04s3

23 pages

ch06s3

ch06s3

16 pages

ch01s3

ch01s3

15 pages

ch03s4

ch03s4

11 pages

ch03s6

ch03s6

6 pages

ch03s5

ch03s5

9 pages

ch03s1

ch03s1

19 pages

ch07s1

ch07s1

11 pages

ch02s1

ch02s1

14 pages

ch08s1

ch08s1

15 pages

ch02s5

ch02s5

9 pages

ch01s4

ch01s4

13 pages

Load more
Download ch06s2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ch06s2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ch06s2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?