How do I efficiently multiply a range of values of an array with a given number?
The naive way would be to linearly iterate the range and multiply with each number in the range. Example: Array: {1,2,3,4,5,6,7,8,9,10}; Multiply index 3 to index 8 with 2. Assuming one based index. Result array should be : {1,2,6,8,10,12,14,16,9,10}; I know that Binary indexed tree can be used for the 'sum' part. How can I efficiently multiply a given range with a number? If you want to actually modify the array, you can't do better than the naive linear algorithm: you have to iterate the entire range and modify each index accordingly. If you mean something like, you have update operations