Results 1 to 2 of 2
  1. #1
    kilyx is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default how to get height of a BFS tree

    This is my code that implements a directed graph.It prints the nodes in bfs order
    but how can i get then the height of the corresponding tree?
    thanks

    Java Code:
      static void BFS(Vector<Vector<Integer>> g,int s){
    		Queue<Integer> q = new LinkedList<Integer>();
    		boolean[] visited=new boolean[g.size()];
    		for(int i=0;i<g.size();i++){
    			visited[i]=false;
    		}
    		    q.offer(s);
    		    System.out.print(s);
    			while(q.isEmpty()==false){
    				int u=q.remove();
    				if (visited[u]==false){
    					visited[u]=true;
    					for ( int x=0;x<g.get(u).size();x++){
    						int v =g.get(u).get(x);
    						q.offer(v);
    						if(visited[v]==false) {
    							System.out.print(" "+v);
    							}
    					}
    				}
    			}
    			
     	}

  2. #2
    kilyx is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default Re: how to get height of a BFS tree

    so i'm wondering if given and adjacency list of a directed graph and its bfs array wich gives me the bfs order of its nodes i can retrieve the height of the bfs tree

Similar Threads

  1. Replies: 2
    Last Post: 11-09-2010, 01:34 PM
  2. Width (-1) and height (-1) cannot be <= 0
    By LovJava in forum AWT / Swing
    Replies: 5
    Last Post: 04-24-2010, 12:16 AM
  3. Replies: 0
    Last Post: 04-04-2010, 07:40 AM
  4. height of the image.
    By programmer_007 in forum Java 2D
    Replies: 13
    Last Post: 02-18-2010, 12:17 PM
  5. dynamising the height of a JPopupMenu
    By iimasd in forum AWT / Swing
    Replies: 6
    Last Post: 11-21-2007, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •