Problem Set 3: Questions To Understand Recursive Complexity Analysis
Problem Set 3: Questions To Understand Recursive Complexity Analysis
Question 1
c- Work out the time complexity for the 3-way merge sort.
Question 2
1 class Demonstration {
2 public static void main( String args[] ) {
3 char[] array = new char[] { 'a', 'b', 'c', 'd' };
4 permutate(array, 0);
5 }
6
7 private static void swap(char[] str, int i, int j) {
8 char temp = str[i];
9 str[i](/learn)
= str[j];
10 str[j] = temp;
}
11 }
12
13 static void permutate(char[] str, int index) {
14
15 // base case
16 if (index == str.length) {
17 System.out.println(str);
18 return;
19 }
20
21 // regular case
22 for (int i = index; i < str.length; i++) {
23 swap(str, index, i);
24 permutate(str, index + 1);
25 swap(str, index, i);
26 }
27 }
28 }
Question 3
As an example, with n=3, we'll get a total of 27 elements. The get and put
methods should be able to specify index from 0 to 26.
notation- notation-
for- for-
interviews- interviews-
Top Down and Bottom Up Approaches Solution Set 3
and- and-
beyond/YM08zoEwKWY) beyond/B8RJXPrVwVx)
Ask a Question
Report an
(https://discuss.educative.io/c/big-o-for-coding-interviews-and-beyond-c-h-
Issue
afzal/recursive-problem-set-3)