Da OOP recht ordentlich ist, um die Implementierung zu abstrahieren, frage ich mich immer noch, welche Art von Zeit-Komplexität eine bestimmte Operation hat, wenn man sie benutzt.Wie kann ich die zeitliche Komplexität eines Methodenaufrufs herausfinden, wenn der Zugriff auf die Quelle hart/nicht möglich ist?
Beispiel: Dokumentation von Collection.min
/**
* Returns the minimum element of the given collection, according to the
* <i>natural ordering</i> of its elements. All elements in the
* collection must implement the <tt>Comparable</tt> interface.
* Furthermore, all elements in the collection must be <i>mutually
* comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
* <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
* <tt>e2</tt> in the collection).<p>
*
* This method iterates over the entire collection, hence it requires
* time proportional to the size of the collection.
*
* @param <T> the class of the objects in the collection
* @param coll the collection whose minimum element is to be determined.
* @return the minimum element of the given collection, according
* to the <i>natural ordering</i> of its elements.
* @throws ClassCastException if the collection contains elements that are
* not <i>mutually comparable</i> (for example, strings and
* integers).
* @throws NoSuchElementException if the collection is empty.
* @see Comparable
*/
Dies ist ein triviales Beispiel, da es leicht zu sehen, wenn an der Quelle suchen, aber es wird noch schwieriger, wenn die Umsetzung komplizierter ist oder nicht sichtbar überhaupt .
Meine Frage: Wie kann ich schnell die Zeit-Komplexität bestimmen, um zu entscheiden, ob es sinnvoll ist zu verwenden? Versuch und Fehler? Zeitprotokollierung?
EDIT: Es ist nicht das beste Beispiel, da es auch in der Dokumentation geschrieben ist, aber die Frage bleibt: Was ist, wenn es nicht in Doku geschrieben ist?
Sie die Dokumentation lesen konnte - es im Snippet ist Sie auf dem Laufenden. –
Die Frage bleibt immer noch, was, wenn ich es nicht in der Doku finden kann? Aktualisiert. – SklogW