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
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 meant by uniform cost search algorithm?
what is software cycle?give a diagramatic representation
What is depth-first search algorithm?
Sorting algorithms and time complexity of various algorithms.
what are the minimum requirements for statr testing?
What is local search algorithms?
When an algorithm is considered completed?
What is the most efficient way to store 1 million phone numbers memory-wise?
Can you pick an algorithm. Write the psuedo-code for a parallel implementation?
What is simulated annealing algorithm?
Which language is used for artificial intelligence?
How are the k-nearest neigh-bors (knn) algorithms different from k-means clustering?
What are the disadvantages of breadth-first search algorithm?
What is the bidirectional search algorithm?