java


Simple code for Breadth First Search Java


I have an ArrayList of arrays like this:
[11, 3]
[2, 3]
[0, 3]
[1, 4]
[5, 4]
[5, 7]
[6, 7]
[7, 8]
[8, 9]
[9, 10]
[0, 5]
I have to implement the breadth first and go from 0 to 1 by via and print all the values by putting them into a separate array.
result should be: [0 5 4 1]
Please someone help me out here. Where to start, and what to do?
Make a simple start to this problem. It looks like you do not understand the general idea of what is going on so lets break it down into steps.
Graph your "tree".
Use your first set of points to draw what the tree (or maze) looks like. You should clearly see the path from 0-5-4-1.
Look into how to do a Breadth-First search. The general pattern is to start at the root and look outwards. I recommend some reading on how to do this properly in theory (https://en.wikipedia.org/wiki/Breadth-first_search).
*Hint (since I am guessing this is homework):
If you run it on that set of data, the first few nodes searched should be 0, 3, 4, 2, 11, 4, 7...*
Lastly, implement it in Java. There is a number of questions already and tutorials online about how to achieve this. My recommendation is look at some of the related content on this website of look it up online.
Unfortunately if you want to continue using the array you have been given (not recommended) it will be a fairly ineffective search. However, here is some pseudo code to get you started.
bfs(starting position)
for each element in the array
find all elements related (connected) to starting position
if(connectedNode = endNode)
end search
else
recursively call this function on the elements found

Related Links

Parse array of objects as array of String using Gson
i am getting NullPoinrException java ( code inside) [duplicate]
Thread.this cannot be referenced from static context" error
How do I modify VirtualDisplay returned by DisplayManager.createVirtualDisplay() method?
Json Object as it is use to an other method outside from AsyncTask Class
android-How to create/copy an xml file from an existing xml file in res/xml
How do I find all Java objects (not classes) with a particular annotation?
“UNAVAILABLE” gRPC failure from android client to python server
Send a file to the server via Spring Security and secure the CSRF
LibGdx Box2d collison not matching up with sprite
Call methods only ONCE per iteration
How to double the number of Days to given Date?
BLE android multiple sensors
Is it possible to execute a runnable JAR and have it run as part of the same process from which it was called?
Matching JAVA SHA-512 to Salesforce's Crypto Generated Digest
Java switch statement about number

Categories

HOME
variables
listview
urbancode
session
relayjs
fme
tesseract
relay
xmpp
rsync
leon
frameworks
umd
google-project-tango
callback
cross-browser
swagger-ui
mapserver
commonmark
leiningen
zebra-printers
dynamics-crm-online
django-simple-history
dosgi
footer
contextmenu
dbext
poltergeist
traffic
ping
objectanimator
microsoft-chart-controls
yadcf
ioio
titanium-mobile
karaf
subset-sum
atl
bytecode-manipulation
revolution-slider
event-driven
twitch
ssjs
preconditions
ensembles
ruby-on-rails-3.1
fakeiteasy
midl
businessworks
boost-multi-index
pg-dump
android-cursor
or-tools
thrust
qpid
master-slave
pickadate
dlna
hexdump
rhino-servicebus
two-factor-authentication
unity-networking
execute
intel-fortran
google-places
icu4j
intellij-14
unity5.2.3
umbraco6
directoryservices
geonetwork
python-green
device-manager
html-helper
heisenbug
sgen
elliptic-curve
funcunit
phpthumb
braille
transcoding
quantlib-swig
sitemesh
chronoforms
jquery-mobile-dialog
sqlperformance
word-processor
pysimplesoap
javaspaces
nsdatecomponents
mercurial-server
zpt
external-accessory
table-footer
remember-me
thunderbird-lightning
web-architecture
libs
phonon
procedural-music
ubuntu-9.04
geneva-server

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App