SlideShare a Scribd company logo
1 of 1
Download to read offline
An Euler cycle in a directed graph is a cycle in which every edge is visited exactly once. Design
an algorithm to test whether a given direct graph has an Euler cycle or not, and if so, find such a
cycle.
Solution
ALGORITHM
Given a starting vertex , the v0algorithm will first find a cycle C starting and ending at v0 such
that C contains all edges going into and out of v0. This can be performed by a walk in the graph.
As we discover vertices in cycle C, we will create a linked list which contains vertices in order
and such that the list begins and ends in vertex v0. We set the current painter to the head of the
list. We now traverse the list by moving our pointer "current" to successive vertices until we
and a vertex which has an outgoing edge which has not been discovered. (If we reach the end of
the list, then we have already found the Eule cycle ). Suppose we find the vertex, vi, that has an
undiscovered outgoing edge. We then take a walk beginning and ending at vi such that all
undiscovered edges containing vi are contained in the walk. We insert our new linked list into
old linked list in place of vi and more "current" to the new neighbor pointed to the first node
containing vi. We continue this process until we search the final node of the linked list, and the
list will then contains an Euler cycle
Running Time of Euler cycle
The algorithm traverse each edge at most twice, first in a walk and second while traversing the
list to find vertices with outgoing edges. Therefore, the total running time of the algorithm is
O(|E|).

More Related Content

More from Bramansinternational

An epidemiologist found five cases ofSolution Epidemiology is .pdf
An epidemiologist found five cases ofSolution Epidemiology is .pdfAn epidemiologist found five cases ofSolution Epidemiology is .pdf
An epidemiologist found five cases ofSolution Epidemiology is .pdf
Bramansinternational
 

More from Bramansinternational (11)

An increase in population would be represented by a movement fromA.pdf
An increase in population would be represented by a movement fromA.pdfAn increase in population would be represented by a movement fromA.pdf
An increase in population would be represented by a movement fromA.pdf
 
An experiment is performed to compare the average reading scores of .pdf
An experiment is performed to compare the average reading scores of .pdfAn experiment is performed to compare the average reading scores of .pdf
An experiment is performed to compare the average reading scores of .pdf
 
An example of the growth factor in common stock is retaining pr.pdf
An example of the growth factor in common stock is retaining pr.pdfAn example of the growth factor in common stock is retaining pr.pdf
An example of the growth factor in common stock is retaining pr.pdf
 
An experiment is performed where a coin is flipped until the first H.pdf
An experiment is performed where a coin is flipped until the first H.pdfAn experiment is performed where a coin is flipped until the first H.pdf
An experiment is performed where a coin is flipped until the first H.pdf
 
An experiment is conducted to examine the effect of punishment on le.pdf
An experiment is conducted to examine the effect of punishment on le.pdfAn experiment is conducted to examine the effect of punishment on le.pdf
An experiment is conducted to examine the effect of punishment on le.pdf
 
An epidemiologist found five cases ofSolution Epidemiology is .pdf
An epidemiologist found five cases ofSolution Epidemiology is .pdfAn epidemiologist found five cases ofSolution Epidemiology is .pdf
An epidemiologist found five cases ofSolution Epidemiology is .pdf
 
An enterprise recently reported an EBITDA of 8million and net income.pdf
An enterprise recently reported an EBITDA of 8million and net income.pdfAn enterprise recently reported an EBITDA of 8million and net income.pdf
An enterprise recently reported an EBITDA of 8million and net income.pdf
 
An experiment consists of selecting an integer X at random from {1,..pdf
An experiment consists of selecting an integer X at random from {1,..pdfAn experiment consists of selecting an integer X at random from {1,..pdf
An experiment consists of selecting an integer X at random from {1,..pdf
 
An entomologist writes an article in a scientific journal which clai.pdf
An entomologist writes an article in a scientific journal which clai.pdfAn entomologist writes an article in a scientific journal which clai.pdf
An entomologist writes an article in a scientific journal which clai.pdf
 
An employer must hire 3 people from a list of 12 applicants. In how .pdf
An employer must hire 3 people from a list of 12 applicants. In how .pdfAn employer must hire 3 people from a list of 12 applicants. In how .pdf
An employer must hire 3 people from a list of 12 applicants. In how .pdf
 
An employer must hire 2 people from a list of 13 applicants. In how .pdf
An employer must hire 2 people from a list of 13 applicants. In how .pdfAn employer must hire 2 people from a list of 13 applicants. In how .pdf
An employer must hire 2 people from a list of 13 applicants. In how .pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

An Euler cycle in a directed graph is a cycle in which every edge is.pdf

  • 1. An Euler cycle in a directed graph is a cycle in which every edge is visited exactly once. Design an algorithm to test whether a given direct graph has an Euler cycle or not, and if so, find such a cycle. Solution ALGORITHM Given a starting vertex , the v0algorithm will first find a cycle C starting and ending at v0 such that C contains all edges going into and out of v0. This can be performed by a walk in the graph. As we discover vertices in cycle C, we will create a linked list which contains vertices in order and such that the list begins and ends in vertex v0. We set the current painter to the head of the list. We now traverse the list by moving our pointer "current" to successive vertices until we and a vertex which has an outgoing edge which has not been discovered. (If we reach the end of the list, then we have already found the Eule cycle ). Suppose we find the vertex, vi, that has an undiscovered outgoing edge. We then take a walk beginning and ending at vi such that all undiscovered edges containing vi are contained in the walk. We insert our new linked list into old linked list in place of vi and more "current" to the new neighbor pointed to the first node containing vi. We continue this process until we search the final node of the linked list, and the list will then contains an Euler cycle Running Time of Euler cycle The algorithm traverse each edge at most twice, first in a walk and second while traversing the list to find vertices with outgoing edges. Therefore, the total running time of the algorithm is O(|E|).