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 <[email protected]>wrote: > 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 <[email protected]> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
