Question: 1. What is the time and space complexities for the following algorithms Problem: Read 5 numbers from the user and print their sum Algorithm
1. What is the time and space complexities for the following algorithms Problem: Read 5 numbers from the user and print their sum Algorithm 1 Read (a) Read (b) Read (c) Read (d) Read (e) Sum a+b+c+d+e Print (sum) Algorithm 2 Sum = 0 For i = 1 to 5 { } Read (a) Sum = sum + a i++ Print (sum) Algorithm 3 Sum = 0 For (i = 1 to 5) { } Read (a[i]) Sum suma [i] i++ Print (sum)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
