Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An useful table to work out with various graphs implementations:</p> <pre><code>OPERATION EDGE LIST ADJ LIST ADJ MATRIX degree(v) O(m) O(d(v)) O(n) incidentEdges(v) O(m) O(d(v)) O(n) areAdjacent(v1,v2) O(m) O(min(d(v1),d(v2)) O(1) addVertex(v) O(1) O(1) O(n²) addEdge(v) O(1) O(1) O(1) removeVertex(v) O(m) O(m) O(n²) removeEdge(e) O(m) O(d(v1)+d(v2)) O(1) memory O(m+n) O(m+n) O(n²) </code></pre> <p>where <code>m</code> is the number of edges, <code>n</code> is the number of vertices and <code>d(vertex)</code> is the number of elements in the vertex adjacency list.. adj matrix implementation has an <code>O(n²)</code> to add and remove vertices because you have to reallocate the matrix..</p> <p>Just prepared this for an article, that why I have it ready :)</p> <p>This is not directly related to benchmarking, since usually you study which operations you will mostly need and choose the right implementation for your needs, so it's a sort of "theoretical" benchmark that you do by studying what you are going to implement. Otherwise you can just measure time that your code needs to do the whole work with both implementations and compare it.</p> <p><strong>EDIT:</strong> since you use a sparse matrix implementation the complexity of operations could slightly change (mostly getting a little worse, since you are trading memory for speed).</p> <p><strong>EDIT2:</strong> ok, now that I know that this is Java it will be fair simple:</p> <pre><code>long before = System.nanoTime(); /* execution of your algorithm */ long elapsed = System.nanoTime() - before; </code></pre> <p>Answer is in nanoseconds and accuracy is not guaranteed, so use this thing carefully. Doing an average of many runs (and checking that variance is low, discarding the result that are more distant from the average) will give coherence to your results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload