Consider the following algorithm, where the array A is indexed 1 through n:
int add_them ( int n , int A[ ] ) {
index i , j , k ;
j = 0 ;
for ( i = 1 ; i <= n ; i++)
j = j + A[i] ;
k = 1 ;
for ( i = 1 ; i <= n ; i++)
k = k + k ;
return j + k ;
}
(a) If n = 5 and the array A contains 2, 5, 3, 7, and 8, what is returned?
(b) What is the time complexity T(n) of the algorithm?
No Answer is Posted For this Question
Be the First to Post Answer
What is breath-first search algorithm?
What are disadvantages uniform cost search algorithm?
Which language is used for artificial intelligence?
When an algorithm is considered completed?
What is depth-first search algorithm?
What is simulated annealing algorithm?
What features would you use to build a recommendation algorithm for users?
list the types of linked list with aid of diagram?
What’s your favorite algorithm, & can you explain it into me in less than a minute?
Which search algorithm will use a limited amount of memory in an online search?
Tell briefly about the Banker's algorithm and what is it used for?
What is the iterative deepening depth-first search algorithm?