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
Explain the Canny's Algorithm.
Name search algorithm technology?
Which is the most straight forward approach for planning algorithms?
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.
What is the bidirectional search algorithm?
What is the depth-first search algorithm?
What’s your favorite algorithm, & can you explain it into me in less than a minute?
What is bidirectional search algorithm?
What features would you use to build a recommendation algorithm for users?
What is the iterative deepening depth-first search algorithm?
What is the breadth-first search algorithm?
What are disadvantages uniform cost search algorithm?
What is iterative deepening depth-first search algorithm?
Explain me what's your favorite algorithm, and can you explain it to me in less than a minute?
What was deep learning, & how does it contrast with other machine learning algorithms?