Consider the following algorithm:
j = 1 ;
while ( j <= n/2) {
i = 1 ;
while ( i <= j ) {
cout << j << i ;
i++;
}
j++;
}
(a) What is the output when n = 6, n = 8, and n = 10?
(b) What is the time complexity T(n)? You may assume that the input n is divisible by 2.



Consider the following algorithm: j = 1 ; while ( j <= n/2) { i = 1 ; while ( i <= j ) { ..

Answer / gokul s

n=6:
(1, 1)
(2, 1)
(2, 2)
(3, 1)
(3, 2)
(3, 3)

n=8:
(1, 1)
(2, 1)
(2, 2)
(3, 1)
(3, 2)
(3, 3)
(4, 1)
(4, 2)
(4, 4)
(4, 4)

n=10:
(1, 1)
(2, 1)
(2, 2)
(3, 1)
(3, 2)
(3, 3)
(4, 1)
(4, 2)
(4, 3)
(4, 4)
(5, 1)
(5, 2)
(5, 3)
(5, 4)
(5, 5)


b) Time complexity is ((n/2) * (n/2)+1)/2

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More AI Algorithms Interview Questions

list the types of linked list with aid of diagram?

0 Answers  


Consider the following algorithm: j = 1 ; while ( j <= n/2) { i = 1 ; while ( i <= j ) { cout << j << i ; i++; } j++; } (a) What is the output when n = 6, n = 8, and n = 10? (b) What is the time complexity T(n)? You may assume that the input n is divisible by 2.

1 Answers  


How are the k-nearest neigh-bors (knn) algorithms different from k-means clustering?

0 Answers  


Which is the most straight forward approach for planning algorithm?

0 Answers  


A* algorithm is based on which search method?

0 Answers  






What is the uniform cost search algorithm?

0 Answers  


When an algorithm is considered completed?

0 Answers  


Give an algorithm for the following problem. Given a list of n distinct positive integers, partition the list into two sublists, each of size n/2, such that the difference between the sums of the integers in the two sublists is minimized. You may assume that n is a multiple of 2.

0 Answers  


what are the minimum requirements for statr testing?

0 Answers   QA,


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

0 Answers  


What is software cycle? Give a diagrammatic representation?

0 Answers  


What is the iterative deepening depth-first search algorithm?

0 Answers  


Categories