objects and pointers
These are just basic data structures like hammar said in another answer, in Java you could represent this with classes like edges and vertices. For example, an edge connects two vertices and can be directional or non-directional and can contain weight. A vertex can have an identifier, name, etc. Most of them have additional properties. Thus, you can build your schedule with them, for example
Vertex a = new Vertex(1); Vertex b = new Vertex(2); Edge edge = new Edge(a,b, 30);
This approach is usually used for object-oriented implementations, since it is more readable and convenient for object-oriented users;).
matrix
A matrix is ββjust a simple two-dimensional array. Assuming you have a vertex identifier that can be represented as an int array as follows:
int[][] adjacencyMatrix = new int[SIZE][SIZE]; // SIZE is the number of vertices in our graph adjacencyMatrix[0][1] = 30; // sets the weight of a vertex 0 that is adjacent to vertex 1
This is commonly used for tight graphs where index access is required. You can imagine a structure un / directional and balanced with it.
adjacency list
This is just a simple data set, I usually implement this with HashMap<Vertex, List<Vertex>> . A similar use could be the HashMultimap in Guava.
This approach is cool because you have a search for vertices O (1) (amortized) and it returns me a list of all adjacent vertices at this particular required vertex.
ArrayList<Vertex> list = new ArrayList<>(); list.add(new Vertex(2)); list.add(new Vertex(3)); map.put(new Vertex(1), list);
This is used to present sparse schedules; if you are applying to Google, you should be aware that the website is sparse. You can handle them in a more scalable way using BigTable .
Oh and BTW, here is a very good summary of this post with fantastic pictures;)
Thomas Jungblut May 04 '11 at 17:23 2011-05-04 17:23
source share