Example of O(n!)?

后端 未结 16 2441
渐次进展
渐次进展 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 23:07

    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?

提交回复
热议问题