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

Post New Answer

More AI Algorithms Interview Questions

What is breath-first search algorithm?

0 Answers  


What are disadvantages uniform cost search algorithm?

0 Answers  


Which language is used for artificial intelligence?

0 Answers   Flextronics,


When an algorithm is considered completed?

0 Answers  


What is depth-first search algorithm?

0 Answers  






What is simulated annealing algorithm?

0 Answers  


What features would you use to build a recommendation algorithm for users?

0 Answers   Twitter,


list the types of linked list with aid of diagram?

0 Answers  


What’s your favorite algorithm, & can you explain it into me in less than a minute?

0 Answers  


Which search algorithm will use a limited amount of memory in an online search?

0 Answers  


Tell briefly about the Banker's algorithm and what is it used for?

0 Answers   Impetus,


What is the iterative deepening depth-first search algorithm?

0 Answers  


Categories