emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[QZ6] Clarification for cycle counting #166

Closed ywu496 closed 3 years ago

ywu496 commented 3 years ago

For the graph below, is it considered two cycles(1<-- 2 <-- 3 <-- 4 <--1 and 1 <-- 5 <-- 4 <-- 1) If it is considered two circles, is it possible to visit all nested circles without traversing any node more than once(I had to traverse the node 4 twice using incoming edges for traversing)? d63fd79da044341a99726e1aa4cfabe

marvinquiet commented 3 years ago

Yes, in this case, you will be visiting node 4 twice because there is a shared edge between two cycles.

jdchoi77 commented 3 years ago

@ywu496 you don't necessarily the node 4 twice, instead you make two separate recursive calls from the node 4 while making 1 visit.