modify this code to find the required output; graph={ 1: [2,3], 2: [1,3], 3: [1,2,5, 4], 4: [6,11,3,5], 5: [7,4,3], 6: [8,4], 7: [5,9], 8: [6], 9: [7,10], 10: [9,12], 11: [12,4], 12: [10,11] }  #perform depth-first search def dfs(graph, start, visited, charge): #current node as visited    visited.add(start) #Check the Roomba needs to enter the charging station    if charge <= 6:     print(f" {start} (Charging, {charge} Wh) -> ")     charge =12    else:      print(f"{start} (Cleaning, {charge} Wh) ->")      charge -= 1 #Take he list of adjacent nodes      adj_nodes = graph[start] #Visit the unvisited adjacent nodes      for node in adj_nodes:       if node not in visited:          dfs(graph, node, visited, charge) #user to enter the starting node start_node = int(input ("Enter starting node: ")) # Perform depth-first search starting from the starting node visited = set() dfs(graph, start_node, visited, 12)     # Sample output Enter starting node: 1 1 (Cleaning, 12 Wh) -> 2 (Cleaning, 11 Wh) -> 3 (Cleaning, 10 Wh) -> 4 (Cleaning, 9 Wh)-> 6 (Cleaning, 8 Wh)-> 8 (Cleaning, 7 Wh)-> 6 (Charging, 6 Wh)-> 4 (Charging, 5 Wh)-> 11 (Charging, 4 Wh)-> 12 (Cleaning, 12 Wh)-> 10 (Cleaning, 11 Wh)-> 9 (Cleaning, 10 Wh)-> 7 (Cleaning, 9 Wh)-> 5 (Cleaning, 8 Wh)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

modify this code to find the required output;

graph={
1: [2,3],
2: [1,3],
3: [1,2,5, 4],
4: [6,11,3,5],
5: [7,4,3],
6: [8,4],
7: [5,9],
8: [6],
9: [7,10],
10: [9,12],
11: [12,4],
12: [10,11]
}
 #perform depth-first search
def dfs(graph, start, visited, charge):
#current node as visited
   visited.add(start)
#Check the Roomba needs to enter the charging station
   if charge <= 6:

    print(f" {start} (Charging, {charge} Wh) -> ")
    charge =12
   else:
     print(f"{start} (Cleaning, {charge} Wh) ->")
     charge -= 1
#Take he list of adjacent nodes
     adj_nodes = graph[start]
#Visit the unvisited adjacent nodes
     for node in adj_nodes:
      if node not in visited:
         dfs(graph, node, visited, charge)
#user to enter the starting node
start_node = int(input ("Enter starting node: "))
# Perform depth-first search starting from the starting node
visited = set()
dfs(graph, start_node, visited, 12)
 
 
# Sample output
Enter starting node: 1
1 (Cleaning, 12 Wh) ->
2 (Cleaning, 11 Wh) ->
3 (Cleaning, 10 Wh) ->
4 (Cleaning, 9 Wh)->
6 (Cleaning, 8 Wh)->
8 (Cleaning, 7 Wh)->
6 (Charging, 6 Wh)->
4 (Charging, 5 Wh)->
11 (Charging, 4 Wh)->
12 (Cleaning, 12 Wh)->
10 (Cleaning, 11 Wh)->
9 (Cleaning, 10 Wh)->
7 (Cleaning, 9 Wh)->
5 (Cleaning, 8 Wh)
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education