SlideShare a Scribd company logo
1 of 1
Download to read offline
An undirected graph is acyclic (i.e., a forest) iff a DFS yields no back edges. Since back edges
are those edges (u, v) connecting a vertex u to an ancestor v in a depth-first tree, so no back
edges means there are only tree edges, so there is no cycle. So we can simply fun DFS. If find a
back edge, there is a cycle. The complexity is O(V ) instead of O(E + V ). Since if there is a back
edge, it must be found before seeing |V | distinct edges. This is because in a acyclic (undirected )
forest, |E| |V | + 1
Solution
An undirected graph is acyclic (i.e., a forest) iff a DFS yields no back edges. Since back edges
are those edges (u, v) connecting a vertex u to an ancestor v in a depth-first tree, so no back
edges means there are only tree edges, so there is no cycle. So we can simply fun DFS. If find a
back edge, there is a cycle. The complexity is O(V ) instead of O(E + V ). Since if there is a back
edge, it must be found before seeing |V | distinct edges. This is because in a acyclic (undirected )
forest, |E| |V | + 1

More Related Content

More from anjanaarts2014

HClO3 + NaOH NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf
                     HClO3 + NaOH  NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf                     HClO3 + NaOH  NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf
HClO3 + NaOH NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdfanjanaarts2014
 
I have already answered it. Check. .pdf
                     I have already answered it. Check.               .pdf                     I have already answered it. Check.               .pdf
I have already answered it. Check. .pdfanjanaarts2014
 
Iodide is a strong nucleophile but a weak base, s.pdf
                     Iodide is a strong nucleophile but a weak base, s.pdf                     Iodide is a strong nucleophile but a weak base, s.pdf
Iodide is a strong nucleophile but a weak base, s.pdfanjanaarts2014
 
NaCl Its the coulombic interaction between Na.pdf
                     NaCl  Its the coulombic interaction between Na.pdf                     NaCl  Its the coulombic interaction between Na.pdf
NaCl Its the coulombic interaction between Na.pdfanjanaarts2014
 
Here Jupiter is the fifth planet from the Sun a.pdf
                     Here  Jupiter is the fifth planet from the Sun a.pdf                     Here  Jupiter is the fifth planet from the Sun a.pdf
Here Jupiter is the fifth planet from the Sun a.pdfanjanaarts2014
 
moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf
                     moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf                     moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf
moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdfanjanaarts2014
 
Lithium is group 1 metal, while nitrogen is group.pdf
                     Lithium is group 1 metal, while nitrogen is group.pdf                     Lithium is group 1 metal, while nitrogen is group.pdf
Lithium is group 1 metal, while nitrogen is group.pdfanjanaarts2014
 
there is some special character in ur question li.pdf
                     there is some special character in ur question li.pdf                     there is some special character in ur question li.pdf
there is some special character in ur question li.pdfanjanaarts2014
 
a.Times Interest Earned Ratio = EBIT interest ExpenseFor 2014.pdf
a.Times Interest Earned Ratio = EBIT  interest ExpenseFor 2014.pdfa.Times Interest Earned Ratio = EBIT  interest ExpenseFor 2014.pdf
a.Times Interest Earned Ratio = EBIT interest ExpenseFor 2014.pdfanjanaarts2014
 
45 yrs.Solution45 yrs..pdf
45 yrs.Solution45 yrs..pdf45 yrs.Solution45 yrs..pdf
45 yrs.Solution45 yrs..pdfanjanaarts2014
 
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdf
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdfthe bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdf
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdfanjanaarts2014
 
ANSWER A for example fluoride, oxide.... etc. .pdf
                     ANSWER A for example fluoride, oxide.... etc.  .pdf                     ANSWER A for example fluoride, oxide.... etc.  .pdf
ANSWER A for example fluoride, oxide.... etc. .pdfanjanaarts2014
 
Java Program import java.io.; import java.util.;public cl.pdf
Java Program import java.io.; import java.util.;public cl.pdfJava Program import java.io.; import java.util.;public cl.pdf
Java Program import java.io.; import java.util.;public cl.pdfanjanaarts2014
 
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdf
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdfH2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdf
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdfanjanaarts2014
 
here reaction is occurring when Sn and I2 are refluxed together redu.pdf
here reaction is occurring when Sn and I2 are refluxed together redu.pdfhere reaction is occurring when Sn and I2 are refluxed together redu.pdf
here reaction is occurring when Sn and I2 are refluxed together redu.pdfanjanaarts2014
 
A) [Sn2+]^3 [Fe3+]^2 (dont include solids) B).pdf
                     A) [Sn2+]^3  [Fe3+]^2 (dont include solids) B).pdf                     A) [Sn2+]^3  [Fe3+]^2 (dont include solids) B).pdf
A) [Sn2+]^3 [Fe3+]^2 (dont include solids) B).pdfanjanaarts2014
 
GivenLOSS Sells a variety of equpiment including the executive off.pdf
GivenLOSS Sells a variety of equpiment including the executive off.pdfGivenLOSS Sells a variety of equpiment including the executive off.pdf
GivenLOSS Sells a variety of equpiment including the executive off.pdfanjanaarts2014
 
Answer for question 1DuPont analysis explains what is affecting co.pdf
Answer for question 1DuPont analysis explains what is affecting co.pdfAnswer for question 1DuPont analysis explains what is affecting co.pdf
Answer for question 1DuPont analysis explains what is affecting co.pdfanjanaarts2014
 

More from anjanaarts2014 (20)

HClO3 + NaOH NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf
                     HClO3 + NaOH  NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf                     HClO3 + NaOH  NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf
HClO3 + NaOH NaClO3 +H2O n(HClO3) = 0.10.04 = 4.pdf
 
The -OCl ion. .pdf
                     The -OCl ion.                                    .pdf                     The -OCl ion.                                    .pdf
The -OCl ion. .pdf
 
I have already answered it. Check. .pdf
                     I have already answered it. Check.               .pdf                     I have already answered it. Check.               .pdf
I have already answered it. Check. .pdf
 
Iodide is a strong nucleophile but a weak base, s.pdf
                     Iodide is a strong nucleophile but a weak base, s.pdf                     Iodide is a strong nucleophile but a weak base, s.pdf
Iodide is a strong nucleophile but a weak base, s.pdf
 
NaCl Its the coulombic interaction between Na.pdf
                     NaCl  Its the coulombic interaction between Na.pdf                     NaCl  Its the coulombic interaction between Na.pdf
NaCl Its the coulombic interaction between Na.pdf
 
Here Jupiter is the fifth planet from the Sun a.pdf
                     Here  Jupiter is the fifth planet from the Sun a.pdf                     Here  Jupiter is the fifth planet from the Sun a.pdf
Here Jupiter is the fifth planet from the Sun a.pdf
 
moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf
                     moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf                     moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf
moles of H+ = 42.0 x 0.120 millimoles = 5.04 mill.pdf
 
Lithium is group 1 metal, while nitrogen is group.pdf
                     Lithium is group 1 metal, while nitrogen is group.pdf                     Lithium is group 1 metal, while nitrogen is group.pdf
Lithium is group 1 metal, while nitrogen is group.pdf
 
there is some special character in ur question li.pdf
                     there is some special character in ur question li.pdf                     there is some special character in ur question li.pdf
there is some special character in ur question li.pdf
 
a.Times Interest Earned Ratio = EBIT interest ExpenseFor 2014.pdf
a.Times Interest Earned Ratio = EBIT  interest ExpenseFor 2014.pdfa.Times Interest Earned Ratio = EBIT  interest ExpenseFor 2014.pdf
a.Times Interest Earned Ratio = EBIT interest ExpenseFor 2014.pdf
 
45 yrs.Solution45 yrs..pdf
45 yrs.Solution45 yrs..pdf45 yrs.Solution45 yrs..pdf
45 yrs.Solution45 yrs..pdf
 
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdf
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdfthe bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdf
the bacteria isolated from the dead mouse is smooth (S) S. pneumonia.pdf
 
ANSWER A for example fluoride, oxide.... etc. .pdf
                     ANSWER A for example fluoride, oxide.... etc.  .pdf                     ANSWER A for example fluoride, oxide.... etc.  .pdf
ANSWER A for example fluoride, oxide.... etc. .pdf
 
Java Program import java.io.; import java.util.;public cl.pdf
Java Program import java.io.; import java.util.;public cl.pdfJava Program import java.io.; import java.util.;public cl.pdf
Java Program import java.io.; import java.util.;public cl.pdf
 
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdf
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdfH2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdf
H2SO4 = 2H+ + SO42-[H+] = 2[H2SO4] = 0.0092 MpH = -log[H+] = 2..pdf
 
here reaction is occurring when Sn and I2 are refluxed together redu.pdf
here reaction is occurring when Sn and I2 are refluxed together redu.pdfhere reaction is occurring when Sn and I2 are refluxed together redu.pdf
here reaction is occurring when Sn and I2 are refluxed together redu.pdf
 
A) [Sn2+]^3 [Fe3+]^2 (dont include solids) B).pdf
                     A) [Sn2+]^3  [Fe3+]^2 (dont include solids) B).pdf                     A) [Sn2+]^3  [Fe3+]^2 (dont include solids) B).pdf
A) [Sn2+]^3 [Fe3+]^2 (dont include solids) B).pdf
 
GivenLOSS Sells a variety of equpiment including the executive off.pdf
GivenLOSS Sells a variety of equpiment including the executive off.pdfGivenLOSS Sells a variety of equpiment including the executive off.pdf
GivenLOSS Sells a variety of equpiment including the executive off.pdf
 
Answer for question 1DuPont analysis explains what is affecting co.pdf
Answer for question 1DuPont analysis explains what is affecting co.pdfAnswer for question 1DuPont analysis explains what is affecting co.pdf
Answer for question 1DuPont analysis explains what is affecting co.pdf
 
3360Solution3360.pdf
3360Solution3360.pdf3360Solution3360.pdf
3360Solution3360.pdf
 

Recently uploaded

MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
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 17Celine George
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
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).pptxneillewis46
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
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 CAPSAnaAcapella
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
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...Nguyen Thanh Tu Collection
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 

Recently uploaded (20)

MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
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
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
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
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
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
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
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...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 

An undirected graph is acyclic (i.e., a forest) iff a DFS yields no .pdf

  • 1. An undirected graph is acyclic (i.e., a forest) iff a DFS yields no back edges. Since back edges are those edges (u, v) connecting a vertex u to an ancestor v in a depth-first tree, so no back edges means there are only tree edges, so there is no cycle. So we can simply fun DFS. If find a back edge, there is a cycle. The complexity is O(V ) instead of O(E + V ). Since if there is a back edge, it must be found before seeing |V | distinct edges. This is because in a acyclic (undirected ) forest, |E| |V | + 1 Solution An undirected graph is acyclic (i.e., a forest) iff a DFS yields no back edges. Since back edges are those edges (u, v) connecting a vertex u to an ancestor v in a depth-first tree, so no back edges means there are only tree edges, so there is no cycle. So we can simply fun DFS. If find a back edge, there is a cycle. The complexity is O(V ) instead of O(E + V ). Since if there is a back edge, it must be found before seeing |V | distinct edges. This is because in a acyclic (undirected ) forest, |E| |V | + 1