Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 01-09-2008, 09:08 PM
hey hey is offline
Member
 
Join Date: Dec 2007
Posts: 21
hey is on a distinguished road
Graph DPS and BFS implementation
Hello everyone,

I'm preparing for an exemption exam. There are a couple of questions I need to solve.((

Given the following Java class definition for a graph
Code:
public class MyGraph<E> { public class Node { E myValue; boolean tag; ArrayList<Node> myNeighbors; } ArrayList<Node> myNodes; void visitNode(Node n) {/* Action to be performed when traversing node */} void deptFirstSearch(Node n) { /* Perform depth-first search of graph starting at n */ } }
i. Write code for the method depthFirstSearch( n ) that performs a depth first traversal
starting at node n.
ii. Write code for the method breadthFirstSearch(n) that performs a breadth first traversal
starting at node n.


I looked through available lectures and there is no code mentioned there, just description of those algorithms.

DFS Traversal Algorithm
for all nodes X
X.tag = False
put 1stnode in Stack
while (Stack not empty )
pop X off Stack
if (X.tag = False)
set X.tag = True
for each successor Y of X
if (Y.tag = False)
push Y onto Stack


BFS Traversal Algorithm
for all nodes X
X.tag = False
put 1stnode in Queue
while ( Queue not empty )
take node X out of Queue
if (X.tag = False)
set X.tag = True
for each successor Y of X
if (Y.tag = False)
put Y in Queue


I was wondering, if someone can helpme with writing a code.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-09-2008, 10:19 PM
hey hey is offline
Member
 
Join Date: Dec 2007
Posts: 21
hey is on a distinguished road
please, help
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
Need Help for Dot Plot Graph BHCluster Java 2D 5 04-15-2008 03:54 PM
Big Faceless Graph Library 2.3.3 JavaBean Java Announcements 0 11-09-2007 11:33 PM
Big Faceless Graph Library 2.3.2 levent Java Announcements 0 08-07-2007 05:28 PM
How to insert graph in java valery Advanced Java 1 08-06-2007 09:38 PM
Help with graph code example silvia Java 2D 1 07-29-2007 11:16 PM


All times are GMT +3. The time now is 12:07 AM.


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