Question
Question: Given a double[ ] A containing N real numbers as input, the partial sums problem specifies the following API describing the basic operations that
Question:
Given a double[ ] A containing N real numbers as input, the partial sums problem specifies the following API describing the basic operations that we need.
add(int i, double y): Add the value y to the ith number.
partialSum(int i): Return the sum of the first i numbers, A[0] through A[i - 1].
There are no insertions or deletions; the only change is to the values of the numbers.
We may introduce one additional array of size N.
Assume for simplicity that N is a power of 2.
It's not allowed to use the segment tree.
Tip: We're allowed to have whatever Big-O time it takes to set up/construct the data structure. It's just the add and partial sum methods that need to be in O(log N).
For the following condition, give a specific English description of a partial sums algorithm that meets the requirements.
- Runtime for add is in O(log N) while partialSum is in O(log N).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started