Update the following algorithm so that it reduced from Θ(n) to Θ(1)
sum = 0;
for i = 1 to n do
sum = sum + i;
Code lines and number of times each line runs
sum = 0; -> 1 time
for i = 1 to n do -> n+1 times
sum = sum + i; -> n times
Time complexity = Θ(n)
This code is calculating sum fo numbers from 1 to n.
We can do same with single line
sum = n*(n+1)/2
So, This code runs Θ(1) time.

sum = n*(n+1)/2

Update the following algorithm so that it reduced from Θ(n) to Θ(1) sum = 0; for...