| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
hard
Recursive Permutation Time Complexity
< Prev
Next >

What is the time complexity of the permute method, which generates all permutations of an array?

public void permute(int[] arr, int start) {
    if(start == arr.length) {
        System.out.println(Arrays.toString(arr));
        return;
    }
    for(int i = start; i < arr.length; i++) {
        swap(arr, start, i);
        permute(arr, start + 1);
        swap(arr, start, i);
    }
}

// Assume swap() correctly swaps two elements in the array.
A

O(n!)

B

O(n log n)

C

O(2^n)

D

O(n^2)

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy