I've got a recursion:
list_to_set([],[]).
list_to_set([A|X],[A|Y]):-
list_to_set(X,Y),
\+member(A,Y).
list_to_set([A|X],Y):-
list_to_set(X,Y),
member(A,Y).
It converts list of elements into a set. For example [1,1,2,3] -> [1,2,3]. When I enter the query list_to_set([1,1,2,3],X).
the result is X = (1,2,3)
and the complexity of finding out the set is O(n)
. Now I can type ;
alternative to make sure, that there is no other possible answer. Obviously there is none and script will return false
. My question is: what is the computational complexity of that second script run, and why?