Choosing data structure

Data structure for my problem

Page 1 of 1

5 Replies - 2416 Views - Last Post: 04 May 2010 - 04:49 PM Rate Topic: -----

#1 majtits   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-May 10

Choosing data structure

Posted 04 May 2010 - 03:06 PM

Hello!

I'm having a problem with this program I want to write. I have bipartite graph and I first want to store vertex from the left side in array, and then under that every vertex I want to save all the edges, that go from that vertex to another (the number of edges varies). I've tries with ArrayList of ArrayList's but I have problems, with searching for existing vertices in the array. So if anyone knows for a better way, or knows how to realize that with ArrayList I would be very grateful.

Greets!

Is This A Good Question/Topic? 0
  • +

Replies To: Choosing data structure

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: Choosing data structure

Posted 04 May 2010 - 03:12 PM

You could try designing your own Generic Graph structure with your own Edge, Vertex, and Graph classes, some of which may use List structures like LinkedList and ArrayList.

I cover custom Graph design in my tutorial on Graphs if you want to check it out. :)
Was This Post Helpful? 1
  • +
  • -

#3 majtits   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-May 10

Re: Choosing data structure

Posted 04 May 2010 - 04:22 PM

I had similar classes than you do, for my graph. But the problem is, that I don't know how to find out if there is all ready some vertex from set A in graphs ArrayList. I need that because then I have to retrieve that vertex from my graph, and add another connection (edge) to it, so it can have multiple connections to vertices from set B.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: Choosing data structure

Posted 04 May 2010 - 04:26 PM

That's why I store a List<Vertex> (or as I refer to it in my tutorial, a List<Edge>) in my Graph class- so you can randomly acces Vertices on the Graph. All interfacing for the Graph is done through the main Graph class, with the Connector and Edge classes running around in the background making things work.
Was This Post Helpful? 0
  • +
  • -

#5 majtits   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-May 10

Re: Choosing data structure

Posted 04 May 2010 - 04:43 PM

Ok, for example ... I make one vertex - vertex1 and then connect him to vertex2 and then add vertex1 to the graph. Then I add some other vertices with only one connection, and then I want to add another vertex to that vertex1 that I added before. My problem is, that I can't retrieve that vertex from my graph is I don't know the number of it's position in the ArrayList, and here is where I'm stuck. :/
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: Choosing data structure

Posted 04 May 2010 - 04:49 PM

If you have a reference to the Vertex, you can use the ArrayList indexOf() method to locate its position. I also included id attributes for my Vertices to help you search. You'll need to have some idea of what you are looking for in your Graph to find it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1