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

easiest way to access json values in java
Spring Quartz Scheduler - Run job after the other has completed
AEM: Changed url for servlets
Count the occurence of word in a list containing sentences
How to call my method
Database issues when tried to migrate app from Appcelerator titanium to Native Java
Android Studio (1.5.1) Rendering Problems when choosing Blank Activity layout
Issues loading .json file from file on Android
Unexpected type error with arrays
Java word shuffle game [closed]
Copy & Rename & Erase in Java
Locking Java task
How to kill or Stop an I/O requesting thread in JAVA?
Error when trying to start a Service in Android
Scala slick: Query field name configurable
Tomcat 7 doesn´t start

Categories

HOME
xamarin
log4j
coq
hook
isabelle
azure-data-factory
path-finding
plone
alfresco
rsync
sqlite-net-extensions
frameworks
jgroups
binary-tree
fsm
icloud
enterprise-library-5
wamp
cross-validation
gitpitch
ups
designer
try-catch
vaadin7
solaris-10
reactive-cocoa
lucene.net
paging
one-hot-encoding
functional-testing
ehcache
strncpy
large-file-upload
gsmcomm
lightswitch-2013
yadcf
phonegap
bytecode-manipulation
io-redirection
devextreme
hockeyapp
abstract-class
objectlistview
theano.scan
hue
webdriver-manager
leading-zero
squib
cubic-spline
long-polling
taffy
atomicity
drupal-6
namecoin
flow-control
arrow-keys
minimization
objective-c-swift-bridge
log4c
nsfilemanager
websitepanel
blackberry-10
rhino-servicebus
ptrace
hsv
intel-fortran
wireshark-dissector
kcachegrind
ami
system32
pretty-print
npapi
dia
rake-task
camanjs
tablelayout
cctv
socketexception
issuu
html-helper
googlemock
terminfo
google-reader
mesa
dml
dealloc
hyprlinkr
soundtouch
file-locking
back-stack
dataadapter
hungarian-algorithm
mqx
jelly
typoscript2
trusted
broken-links
first-responder
propertyeditor
dsn
cascalog
newtonscript
jspinclude
ticoredatasync
qtkit
dotnethighcharts
custom-backend
django-tagging
file-comparison
createwindow
firefox-5
substrings
ctp4
data-acquisition
wsdl.exe
windows-live-messenger
lzh
document-conversion
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App