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

Which language is used for artificial intelligence?

0 Answers   Flextronics,


What is meant by uniform cost search algorithm?

0 Answers  


What is the breadth-first search algorithm?

0 Answers  


What is breath-first search algorithm?

0 Answers  


What is meant by a * search algorithm?

0 Answers  






A lot of questions were asked on sorting for eg. Best algorithm on the basis of number of swaps, number of comparisons etc.

0 Answers   DELL,


Define Routing Algorithm?

0 Answers   Maveric,


What is bidirectional search algorithm?

0 Answers  


Given a sorted array of n integers that has been rotated i(unknown) number of times, give a (log n) algorithm that finds an element in the array.

0 Answers   Expedia,


What is breadth-first search algorithm?

0 Answers  


What was deep learning, & how does it contrast with other machine learning algorithms?

0 Answers  


Give a general algorithm for converting a m-array tree to a 2-ary tree.

0 Answers   Tech Mahindra,


Categories