Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 11:52 PM
Member
 
Join Date: Feb 2008
Posts: 8
JavaInLove is on a distinguished road
Graph - Breadth First search for searching a node ?
Hello

This is probably not a Java Coding problem but is a Programming Algorithm problem that i need to implement in Java which i cannot get.

Im sure most programmers would know that Breadth First Search (commonly known as Breadth First Traversal) goes through every element in the Graph and return a list of element(or nodes) visited. Breadth First Search mostly used for searching Graphs.

My graph is directed graph

1. Put the root node on the queue.
2. Pull a node from the beginning of the queue and examine it.
2.1. If the searched element is found in this node, quit the search and return a result.
2.2. Otherwise push all the (so-far-unexamined) successors (the direct child nodes) of this node into the end of the queue, if there are any.
3. If the queue is empty, every node on the graph has been examined -- quit the search and return "not found".
4. Repeat from Step 2.

Above algorithm is Breadth First Search in its general form - So how will i modify it so that once it has found its target node, it will:
1. Quit Search
2. Return a list of previous node that visited from root node to get to target node
(But there's a catch*)

*What i want is not return all nodes visited but the list of nodes which contains the path from root node to target node.

How?

Thanks in advance
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-07-2008, 12:17 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
What is your question? This is a trivial tree traversal code.

You have the right idea. Just implement it.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary Search searching news Article peterdfl New To Java 0 09-26-2008 01:57 AM
make search function ike eclipse search in window->preference i4ba1 Advanced Java 5 08-26-2008 05:43 PM
How to disabled a node. smartsubroto New To Java 32 07-01-2008 09:30 AM
Node selection in jtree Preethi AWT / Swing 4 06-20-2008 01:25 AM
Breadth First Search and Friends! nokomis New To Java 0 11-09-2007 10:16 PM


All times are GMT +3. The time now is 04:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org