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

Consider the following algorithm: for ( i = 2 ; i <= n ; i++) { for ( j = 0 ; j <= n) { cout << i << j ; j = j + floor(n/4) ; } } (a) What is the output when n = 4 (b) What is the time complexity T(n). You may assume that n is divisible 4.

0 Answers  


Draw a flowchart to find the average of four number?

0 Answers  


What is iterative deepening depth-first search algorithm?

0 Answers  


What is breath-first search algorithm?

0 Answers  


When an algorithm is considered completed?

0 Answers  


What is greedy best first search algorithm?

0 Answers  


What is meant by uniform cost search algorithm?

0 Answers  


Explain me what's your favorite algorithm, and can you explain it to me in less than a minute?

0 Answers  


What are the disadvantages of breadth-first search algorithm?

0 Answers  


Which algorithm is used for solving temporal probabilistic reasoning?

0 Answers  


What do you mean by overfitting and underfitting algorithms?

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,


Categories
  • AI Algorithms Interview Questions AI Algorithms (74)
  • AI Natural Language Processing Interview Questions AI Natural Language Processing (96)
  • AI Knowledge Representation Reasoning Interview Questions AI Knowledge Representation Reasoning (12)
  • AI Robotics Interview Questions AI Robotics (183)
  • AI Computer Vision Interview Questions AI Computer Vision (13)
  • AI Neural Networks Interview Questions AI Neural Networks (66)
  • AI Fuzzy Logic Interview Questions AI Fuzzy Logic (31)
  • AI Games Interview Questions AI Games (8)
  • AI Languages Interview Questions AI Languages (141)
  • AI Tools Interview Questions AI Tools (11)
  • AI Machine Learning Interview Questions AI Machine Learning (659)
  • Data Science Interview Questions Data Science (671)
  • Data Mining Interview Questions Data Mining (120)
  • AI Deep Learning Interview Questions AI Deep Learning (111)
  • Generative AI Interview Questions Generative AI (153)
  • AI Frameworks Libraries Interview Questions AI Frameworks Libraries (197)
  • AI Ethics Safety Interview Questions AI Ethics Safety (100)
  • AI Applications Interview Questions AI Applications (427)
  • AI General Interview Questions AI General (197)
  • AI AllOther Interview Questions AI AllOther (6)