big o - What Big-O notation would this fall under? -



big o - What Big-O notation would this fall under? -

what big-o notation fall under? know setsearch() , removeat() of order o(n) (assume either way). know without loop it'd o(n), certain, confused how calculate becomes loop thrown it. i'm not great @ math... so. o(n^2)?

public void removeall(dataelement clearelement) { if(length == 0) system.err.println("cannot delete empty list."); else { for(int = 0; < list.length; i++) { loc = seqsearch(clearelement); if(loc != -1) { removeat(loc); --i; } } } }

if removeat() , seqsearch() o(n) respect length of list yes, algorithm of order o(n^2). because within loop phone call seqsearch every time, possibility of calling removeat(loc). means each iteration doing either n or 2n operations. taking worst case, have 2n^2 operations o(n^2).

big-o

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -