For the following recursive functions, give the worst case and best case running time in the appropriate O(·), Ω(·), or Θ(·) notation. 1.1 Give the running time in terms of N.
1 2 3 4 5 6 7 8
publicvoidandslam(int N) { if (N > 0) { for (inti=0; i < N; i += 1) { System.out.println("datboi.jpg"); } andslam(N / 2); } }
The worst case and best case is all $\Theta(n)$
1.2 Give the running time for andwelcome(arr, 0, N) where N is the length of the input array arr.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
publicstaticvoidandwelcome(int[] arr, int low, int high) { System.out.print("[ "); for (inti= low; i < high; i += 1) { System.out.print("loyal "); } System.out.println("]"); if (high - low > 0) { doublecoin= Math.random(); if (coin > 0.5) { andwelcome(arr, low, low + (high - low) / 2); } else { andwelcome(arr, low, low + (high - low) / 2); andwelcome(arr, low + (high - low) / 2, high); } } }