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
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
.
Any algorithm that calculates all permutation of a given array is O(N!)
.
In Wikipedia
Solving the traveling salesman problem via brute-force search; finding the determinant with expansion by minors.
http://en.wikipedia.org/wiki/Big_O_notation#Orders_of_common_functions
the simplest example :)
pseudocode:
input N
calculate N! and store the value in a vaiable NFac - this operation is o(N)
loop from 1 to NFac and output the letter 'z' - this is O(N!)
there you go :)
As a real example - what about generating all the permutations of a set of items?