Re: [algogeeks] Tree/Graph implementation

2012-05-31 Thread Mad Coder
@Gene: Can you tell some other ways of graph representation in case of
sparse matrix as till now I consider adjacency list as the best method for
the same.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Tree/Graph implementation

2012-05-29 Thread prakash y
How to implement complex data structures like trees (with unknown no.of
subtrees) and graphs efficiently in C/Java?
I have implemented binary trees in Java as it always contains two nodes.
But I don't know about graphs.
I am not able to solve these problems in coding contests because of this.
Can anyone please suggest me?

Thanks in advance.
~Prakash.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread Hassan Monfared
you can use adjacency matrices for spare graphs and two dimensional  array
for non-spare graphs

On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.com wrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of this.
 Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread Jeevitesh
We can use the following data structure for Graphs:-
- Adjacency Lists(More generally used)
- Adjacency Matrix(Takes a lot of space but good for dense graph)

For Trees:-
We can model a node such that it has two pointers one of which points to
its first child while the other points to the next peer or sibling.

On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional  array
 for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.com wrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of this.
 Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
*Thanks,
Jeevitesh Shekhar Singh.*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread prakash y
@all,
when we use a 2D array/matrix to implement graphs, how can we traverse
efficiently from starting node to ending node?

take a look at of these problems
Graph problem:
https://www.interviewstreet.com/challenges/dashboard/#problem/4f40dfda620c4
Tree Problem:
https://codeninja.interviewstreet.com/challenges/dashboard/#problem/4f75c32310103

How can we implement such problems efficiently in a language like Java?

On Tue, May 29, 2012 at 4:07 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 We can use the following data structure for Graphs:-
 - Adjacency Lists(More generally used)
 - Adjacency Matrix(Takes a lot of space but good for dense graph)

 For Trees:-
 We can model a node such that it has two pointers one of which points to
 its first child while the other points to the next peer or sibling.


 On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional
 array for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.comwrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two nodes.
 But I don't know about graphs.
 I am not able to solve these problems in coding contests because of
 this. Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Tree/Graph implementation

2012-05-29 Thread atul anand
simple DFS can be used to traverse nodes in the graph

On Wed, May 30, 2012 at 10:12 AM, prakash y yprakash@gmail.com wrote:

 @all,
 when we use a 2D array/matrix to implement graphs, how can we traverse
 efficiently from starting node to ending node?

 take a look at of these problems
 Graph problem:
 https://www.interviewstreet.com/challenges/dashboard/#problem/4f40dfda620c4
 Tree Problem:
 https://codeninja.interviewstreet.com/challenges/dashboard/#problem/4f75c32310103

 How can we implement such problems efficiently in a language like Java?

 On Tue, May 29, 2012 at 4:07 PM, Jeevitesh 
 jeeviteshshekha...@gmail.comwrote:

 We can use the following data structure for Graphs:-
 - Adjacency Lists(More generally used)
 - Adjacency Matrix(Takes a lot of space but good for dense graph)

 For Trees:-
 We can model a node such that it has two pointers one of which points to
 its first child while the other points to the next peer or sibling.


 On Tue, May 29, 2012 at 4:03 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can use adjacency matrices for spare graphs and two dimensional
 array for non-spare graphs


 On Tue, May 29, 2012 at 2:47 PM, prakash y yprakash@gmail.comwrote:

 How to implement complex data structures like trees (with unknown no.of
 subtrees) and graphs efficiently in C/Java?
 I have implemented binary trees in Java as it always contains two
 nodes. But I don't know about graphs.
 I am not able to solve these problems in coding contests because of
 this. Can anyone please suggest me?

 Thanks in advance.
 ~Prakash.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.