0

The “APS” (All Possible Sorting) algorithm sorts an array A of size n by generating all possible sequences of elements of n, and for each sequence, checking to see if the elements are in sorted (ascending) order.

a) What is the worst-case time complexity of APS? Explain your logic / show your work.

My answer:

Worst case is O(n!) because it generates all possible sequences and then checks if sorted.

Preferably, I would like someone to tell me if I'm right or wrong and how to get to the answer. This big O stuff confuses me.

1 Answer 1

3

APS is generating all possible permutations of N elements, which gives you n! different possible sortings, so you are correct.

Proving that it is O(n!) just requires you to prove that the runtime is asymptotically upper-bounded by n!, which basically means you have to prove that:

f(n) = O(n!) if, for some m and c, |f(n)| < |m * n!| for all n > c.

Proving this is easier if you have the actual algorithm written out, but if you walk through your logic it should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.