Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of a factorial time algorithm O( n! )

I'm studying time complexity in school and our main focus seems to be on polynomial time O(n^c) algorithms and quasi-linear time O(nlog(n)) algorithms with the occasional exponential time O(c^n) algorithm as an example of run-time perspective. However, dealing with larger time complexities was never covered.

I would like to see an example problem with an algorithmic solution that runs in factorial time O(n!). The algorithm may be a naive approach to solve a problem but cannot be artificially bloated to run in factorial time.

Extra street-cred if the factorial time algorithm is the best known algorithm to solve the problem.

like image 281
recursion.ninja Avatar asked May 15 '13 02:05

recursion.ninja


People also ask

What is O n !) time complexity?

Linear time complexity O(n) means that the algorithms take proportionally longer to complete as the input grows. Examples of linear time algorithms: Get the max/min value in an array. Find a given element in a collection.

How do you find the time complexity of a factorial function?

To represent in Big-Oh notation, T(N) is directly proportional to n, Therefore, The time complexity of recursive factorial is O(n). As there is no extra space taken during the recursive calls,the space complexity is O(N).

Which algorithm has O 2 n time complexity?

O(2n) An example of an O(2n) function is the recursive calculation of Fibonacci numbers. O(2n) denotes an algorithm whose growth doubles with each addition to the input data set.


2 Answers

Generate all the permutations of a list

You have n! lists, so you cannot achieve better efficiency than O(n!).

like image 141
zw324 Avatar answered Nov 05 '22 00:11

zw324


Traveling Salesman has a naive solution that's O(n!), but it has a dynamic programming solution that's O(n^2 * 2^n)

like image 44
Zim-Zam O'Pootertoot Avatar answered Nov 05 '22 02:11

Zim-Zam O'Pootertoot