educative.io

What do you mean by An array of size N has an order of N^2 subarray.?

What do you mean by An array of size N has an order of N^2 subarray.?


Course: Competitive Programming in C++: The Keys to Success - Learn Interactively
Lesson: Introduction - Competitive Programming in C++: The Keys to Success

It means the number of subarrays in the array is proportional to N^2. In other words, as the size of the array increases, the number of subarrays increases at a rate that is approximately quadratic in N.

An array of size N has N*(N+1)/2 total subarrays, which is of the order of N^2. This is because for each element in the array, we can create N subarrays that start at that element, and then we need to add one more subarray that consists of that element alone. Therefore, the total number of subarrays is the sum of the first N natural numbers, which is equal to N*(N+1)/2.