What will be the worst case time complexity of finding the sum of elements in a given range of (l,r) in an array of size n when we use square root optimization?
What will be the worst case time complexity of finding the sum of elements in a given range of (l,r) in an array of size n when we use square root optimization? Correct Answer O(√n)
When we use square root optimization we decompose the given array into √n chunks each of size √n. So after calculating the sum of each chunk individually, we require to iterate only 3*√n times to calculate the sum in the worst case.
মোঃ আরিফুল ইসলাম
Feb 20, 2025