I have an algorithm manipulating a list, and I would like to express its complexity.
In the algorithm, I have List.mem a l inside a loop, and I am not sure how to consider the complexity of List.mem, must it be O(List.length(l)), or Ocaml can do something magic inside to be better than O(List.length(l))?
There’s no magic, here’s the implementation (OCaml 3.12.0):
If you have an OCaml source distribution, this is in the file named
stdlib/list.ml(line 135).