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
Define Routing Algorithm?
What do you mean by overfitting and underfitting algorithms?
What are the complexities of sorting algorithms and how can this complexity be calculated?
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 depth-first search algorithm?
Explain me what's your favorite algorithm, and can you explain it to me in less than a minute?
Write an algorithm to traverse a knight covering all the squares on a chessboard starting at a particular point.
What is iterative deepening depth-first search algorithm?
What is bidirectional search algorithm?
What is the uniform cost search algorithm?
What is the breadth-first search algorithm?
A* algorithm is based on which search method?
Tell us how will you know which machine learning algorithm to choose for your classification problem?
What is the bidirectional search algorithm?
What is breath-first search algorithm?