Example of O(n!)?

后端 未结 16 2454
渐次进展
渐次进展 2020-11-30 22:20

What is an example (in code) of a O(n!) function? It should take appropriate number of operations to run in reference to n; that is, I\'m asking a

16条回答
  •  感情败类
    2020-11-30 22:58

    printf("Hello World");

    Yes, this is O(n!). If you think it is not, I suggest you read the definition of BigOh.

    I only added this answer because of the annoying habit people have to always use BigOh irrespective of what they actually mean.

    For instance, I am pretty sure the question intended to ask Theta(n!), at least cn! steps and no more than Cn! steps for some constants c, C > 0, but chose to use O(n!) instead.

    Another instance: Quicksort is O(n^2) in the worst case, while technically correct (Even heapsort is O(n^2) in the worst case!), what they actually mean is Quicksort is Omega(n^2) in the worst case.

提交回复
热议问题