Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Depth First Search. How to write a public List dfs(String from) method in java : This is the useful algorithms: Depth First Search: DFS at

image text in transcribed

Depth First Search. How to write a public List dfs(String from) method in java :

This is the useful algorithms:

Depth First Search:

DFS at a node(visiting a node):

this.visited=true

for neighbor in node.neighbors():

if(!neighbor.Discovered)

neighbor.setDiscovered(true)

print(neighbor)

node.setVisited(true)

for neighbor in neighbors:

if(!neighbor.visited):

neighbor.visit()

Sample:

Cities: //Alphabetical Order

---------------------

Bones Beach

Composting Fields

Fire Hazard

Fishingville

Gatsby

Kingkongoma

Lawn City

North Spoon

Small Pear

South Spoon

Stream Foot

University

Road Capacity

----------------------------------------------

Composting Fields to Small Pear 12

Lawn City to Small Pear 30

Hipster to Small Pear 14

Hipster to Small Pear 16

Lawn City to Hipster 16

Gatsby to Composting Fields 10

Fishingville to Lawn City 17

Fishingville to Gatsby 11

Bones Beach to Hipster 12

Bones Beach to Lawn City 8

Fire Hazard to Bones Beach 13

Kingkongoma to Fire Hazard 7

Kingkongoma to Lawn City 20

University to Kingkongoma 6

University to Fishingville 18

Stream Foot to University 6

Steam Foot to Kingkongoma 11

North Spoon to Stream Foot 15

South Spoon to Stream Foot 20

D) Destinations reachable (Depth First Search)

Please select an option: D

Please enter a starting city: University

DFS Starting From University:

Fishingville,Gatsby,Composting Fields, Small Pear,Lawn City, Hipster,Kingkongoma,Fire Hazard,BonesBeach

Traffic Flaw North Spoon Small Pear Composting Fields 15 18 10 Stream Foot 12 Gatsby 30 Fishingvile South Spoon 7Kingkongoma Fire Hazard Lawn City 2D 14 12 Traffic Flaw North Spoon Small Pear Composting Fields 15 18 10 Stream Foot 12 Gatsby 30 Fishingvile South Spoon 7Kingkongoma Fire Hazard Lawn City 2D 14 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago