Time complexity for java ArrayList

An ArrayList in Java is a List that is backed by an array. The get(index) method is a constant time, O(1), operation. The code straight out of the Java library for ArrayList.get(index): public E get(int index) { RangeCheck(index); return (E) elementData[index]; } Basically, it just returns a value straight out of the backing array. (RangeCheck(index)) … Read more

Complexity of ISO Prolog predicates

tl;dr: No and no. Let’s start with sort/2 which ideally would need n ld(n) comparisons. Fine, but how long does one comparison take? Let’s try this out: tails(Es0, [Es0|Ess]) :- Es0 = [_|Es], tails(Es, Ess). tails([],[[]]). call_time(G,T) :- statistics(runtime,[T0|_]), G, statistics(runtime,[T1|_]), T is T1 – T0. | ?- between(12,15,I), N is 2^I, length(L,N),maplist(=(a),L), tails(L,LT), call_time(sort(LT,LTs), … Read more