All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0201_0300.s0300_longest_increasing_subsequence.complexity.md Maven / Gradle / Ivy

There is a newer version: 1.35
Show newest version
**Time Complexity (Big O Time):**

1. The program uses dynamic programming to find the LIS. It iterates through the input array `nums`, which has 'n' elements.
2. Inside the loop, a binary search is performed on the `dp` array to find the appropriate position to update. Binary search has a time complexity of O(log n).
3. The binary search is performed for each element in `nums`, so the total time complexity for the binary search part is O(n * log n).
4. The loop also includes constant-time operations, so the overall time complexity of the program is O(n * log n).

**Space Complexity (Big O Space):**

1. The program uses an additional integer array `dp` of length `nums.length + 1` to store intermediate results. Therefore, the space complexity is O(n) for the `dp` array.

In summary, the provided program has a time complexity of O(n * log n) and a space complexity of O(n) due to the dynamic programming array `dp`.




© 2015 - 2024 Weber Informatics LLC | Privacy Policy