-1

For python built-in functions such as:

sorted()
min()
max()

what are time/space complexities, what algorithms are used?

Is it always advisable to use the built-in functions of python?

bilucent
  • 108
  • 1
  • 10
  • see https://stackoverflow.com/q/1517347/3768871 for `sorted` – OmG Dec 09 '18 at 17:48
  • Yes, it is advisable to use the built-in functions of python. They are debugged, documented, and optimised. Many are written in C, all ae written by very good coders. – rici Dec 10 '18 at 03:21

1 Answers1

0

As mentioned in comments, sorted is timsort (see this post) which is O(n log(n)) and a stable sort. max and min will run in Θ(n). But, if you want to find both of them in a solution, you can find them using 3n/2 comparison instead of 2n. (Although in general they are in O(n)). To know more about the method see this post.

jpp
  • 159,742
  • 34
  • 281
  • 339
OmG
  • 18,337
  • 10
  • 57
  • 90