Solutions
Algorithm #1
- Worst-Case Time Complexity: O(n)
- Reasoning: Splitting the phrase and iterating through the words both operate in linear time relative to the length of the phrase.
Algorithm #2
- Worst-Case Time Complexity: O(n^2)
- Reasoning: Nested loops each iterating up to the length of the list.
Algorithm #3
- Worst-Case Time Complexity: O(n)
- Reasoning: Recursion occurs n times before reaching the base case.
Algorithm #4
- Worst-Case Time Complexity: O(1)
- Reasoning: Always checks the first element of the array.
Algorithm #5
- Worst-Case Time Complexity: O(n)
- Reasoning: Iterates through the input string twice (once to push onto the stack and once to pop from it).
Algorithm #6
- Worst-Case Time Complexity: O(n)
- Reasoning: Iterates from 1 to n-1.
Algorithm #7
- Worst-Case Time Complexity: O(n)
- Reasoning: Each of the two forEach loops iterates through the array independently.
Algorithm #8
- Worst-Case Time Complexity: O(n)
- Reasoning: Iterates from 2 to num-1.