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.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the Canny's Algorithm.

584


Name search algorithm technology?

613


Which is the most straight forward approach for planning algorithms?

597


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.

2167


What is the bidirectional search algorithm?

571






What is the depth-first search algorithm?

588


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

811


What is bidirectional search algorithm?

703


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

580


What is the iterative deepening depth-first search algorithm?

534


What is the breadth-first search algorithm?

523


What are disadvantages uniform cost search algorithm?

1209


What is iterative deepening depth-first search algorithm?

541


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

677


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

534