Question: ( 1 0 points ) Finding cycles Press shift enter to test your code. Ensure that your code has been saved first by pressing shift

(10 points) Finding cycles Press shift enter to test your code. Ensure that your code has been saved first by pressing shift+enter on the previous cell.
from IPython.core.display import display, HTML
def part_of_a_cycle_test():test_cases =[([[1,3],[],[1,3],[2]],0, False),([[],[0,2],[3],[1]],0, False),([[1,2],[4,5],[3,4],[8,9],[7,8],[6,7],[],[],[],[]],0, False)for (test_graph, starting_node, solution) in test_cases: if (solution != output): s2=''+ str(solution)+' Your code output: '+ str(output)+"" failed = True display(HTML('')) display(HTML(''))
part_of_a_cycle_test()/tmp/ipykernel_124/1471569436.py:3: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display
from IPython.core.display import display, HTML
Failed - test case: Inputs: graph =[1,3],[1,[1,3],[2]] node 2
Expected Output: True Your code output: False
One or more tests failed.
Write a function that returns whether a node is part of a cycle.
HINT: Modify you DFS to return early when it finds a cycledef part_of_a_cycle(a, u): color[u]= 'GRAY' if color[v]== 'WHITE': return True color[u]= 'BLACK'n = len(a)return dfs(a, u, color, -1)
def detect_cycle(a):color =['WHITE']* n if color[u]== 'WHITE': return True
Testing below
 (10 points) Finding cycles Press shift enter to test your code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!