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

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

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

The time complexity of this program is O(n), where 'n' is the length of the input array `nums`. This is because the program iterates through the entire array exactly once in a single pass. The loop runs 'n' times, and inside the loop, there are constant-time operations such as checking and swapping elements.

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

The space complexity of the program is O(1), which indicates constant space usage. Regardless of the size of the input array, the program only uses a constant amount of extra space to store integer variables (`firstZero`, `i`, and `val2`) and does not use any additional data structures whose space requirements depend on the input size. The space used for these variables remains constant.

In summary, the provided program has a time complexity of O(n), where 'n' is the length of the input array `nums`, and it has a space complexity of O(1), indicating constant space usage.




© 2015 - 2024 Weber Informatics LLC | Privacy Policy