Discrete Mathematics with Graph Theory (3rd Edition) 347

# Discrete Mathematics with Graph Theory (3rd Edition) 347 -...

This preview shows page 1. Sign up to view the full content.

Section 12.4 345 Step 3: Otherwise (all the vertices of the current V have indegree at least 1, so V contains a cycle) Let Uo be any vertex of V, let U = {uo} and let k = 0; While k :::; n - 1, • Find x E V for which XUk is an arc and let Uk+1 = x; • Replace V by V " {x} and U by U U {x}. If Uk+l E U, find the largest j with Uj = Uk+1, output the cycle Uj, Uj+l, ... , Uk+l and stop; otherwise replace k by k + 1. end while (c) Here is Maple code (output suppressed) which does the job for a digraph, known to possess a cycle, with vertices 1,2, ... ,n and adjacency matrix A. The output is a cycle Ui, Ui+1. ... ,Uj. > restart: > with(linalg): #to permit definition of matrix
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .- {seq( i, i=l .. n )}; #vertex set > v := vector(n); #v[l], v[2], ... , are the vertices > for i to n do v[i] := -1: od: > for i to n do indeg[i] .- 0: od: #at the start of a canonical #labeling #initialize v > for i to n do #find original indegrees od: for j to n do indeg[i] .-indeg[i] + A[j,i]: od: > t := 1: > found := 1: #found = 1 as long as we continue to find #vertices of a canonical labeling > while((found=l) and (t <= n)) do found := 0: i := 0: while(i < n) do i := i+1: od: if ((member(i,V)=true) and (indeg[i]=O)) then v[t] := i; fi: t := t+1: V := V minus {v[t]}: for j in V do #find indegrees for new V od: if (A[i,j]=l) then indeg[j] .-indeg[j] - 1: fi: found := 1:...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online