foo(anElem) {
return this.linearSearch(anElem);
}
linearSearch(anElem) { //Return matching element //or null if no match let i = 0 while (i < this.size()) { let nextElem = this.get(i) if (nextElem.equals(anElem)) return nextElem i++ } return null }
O(n) + O(1) + O(1)
O(n)
foo(anElem) { this.linearSearch(anElem); this.linearSearch(anElem); }
O(n) + O(n) = 2 * O(n)
2 * O(n) = O(n)
Given data structure "structure" Algorithm #1: O(1) Do a complex user interface (UI) operation that does not depend on structure size. Assume UI takes about one minute to complete Algorithm #2: O(n) Do Linear Search of "structure"