Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help, Im not sure why my dfs algorithm is not passing test cases and producing inccor#dfs ( a ) performs a depth first search
Please help, Im not sure why my dfs algorithm is not passing test cases and producing inccor#dfsa performs a depth first search starting at node and returns a list of nodes in the order in which they were seen, with start and stop times. Press shift enter to test your code. Ensure that your code has been saved first by pressing shiftenter on the previous cell.
from IPython.core.display import display, HTML
def dfstest:testcases for testgraph, solution in testcases: if solution output: s strsolution Your code output: stroutput failed True displayHTML displayHTML
dfstesttmpipykernelpy:: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython please import from IPython display
from IPython.core.display import display, HTML
Failed test case: Inputs: graph
Expected Output: Your code output:
Failed test case: Inputs: graph
Expected Output: Your code output:
One or more tests failed.
#INPUT: a node cycle
#OUTPUT:
def dfsvisita u color, d f time, result:du timefor v in au: dfsvisita v color, d f time, resulttimeresult.appendudu fu
def dfsa:color WHITE nf nresult if coloru 'WHITE':result.sortkeylambda x: x # Sort based on discovery timesect output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started