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
Explain me what's your favorite algorithm, and can you explain it to me in less than a minute?
What is Na?ve Bayes Algorithm?
Given a series of positive integers. Design an efficient algorithm that can detect pairs whose sum is equal to K such that K = ei + ej, and (i not equal to j).
What is the uniform cost search algorithm?
What is simulated annealing algorithm?
What was deep learning, & how does it contrast with other machine learning algorithms?
Write the Shortest path algorithm for a graph.
What is the most efficient way to store 1 million phone numbers memory-wise?
What is Back propagation in Neural Networks?
1. Consider the following algorithm: for ( i = 1 ; i <= 1 . 5 n ; i++) cout << i ; for ( i = n ; i >= 1 ; i - - ) cout << i ; (a) What is the output when n = 2, n = 4, and n = 6? (b) What is the time complexity T(n)? You may assume that the input n is divisible by 2.
Which algorithm inverts a complete resolution strategy?
Why size of integer depends on the machine architecture then what the best sorting algorithm and why?
0 Answers HPCL, Hughes Systique Corporation,
AI Algorithms (74)
AI Natural Language Processing (96)
AI Knowledge Representation Reasoning (12)
AI Robotics (183)
AI Computer Vision (13)
AI Neural Networks (66)
AI Fuzzy Logic (31)
AI Games (8)
AI Languages (141)
AI Tools (11)
AI Machine Learning (659)
Data Science (671)
Data Mining (120)
AI Deep Learning (111)
Generative AI (153)
AI Frameworks Libraries (197)
AI Ethics Safety (100)
AI Applications (427)
AI General (197)
AI AllOther (6)