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
Can you list some use cases where classification machine learning algorithms can be used?
What is the bidirectional search algorithm?
Which is the most straight forward approach for planning algorithms?
What features would you use to build a recommendation algorithm for users?
what is software cycle?give a diagramatic representation
What are the disadvantages of depth-first search algorithm?
What is the most efficient way to store 1 million phone numbers memory-wise?
What’s your favorite algorithm, & can you explain it into me in less than a minute?
Can you pick an algorithm. Write the psuedo-code for a parallel implementation?
How are the k-nearest neigh-bors (knn) algorithms different from k-means clustering?
Sorting algorithms and time complexity of various algorithms.
What is greedy best first search algorithm?
What are the complexities of sorting algorithms and how can this complexity be calculated?
Which search algorithm will use a limited amount of memory in online search?
Explain the Canny's Algorithm.