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 / 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 |
Given a sorted array of n integers that has been rotated i(unknown) number of times, give a (log n) algorithm that finds an element in the array.
Which language is used for artificial intelligence?
A lot of questions were asked on sorting for eg. Best algorithm on the basis of number of swaps, number of comparisons etc.
List the different algorithm techniques in machine learning?
What is breadth-first search algorithm?
What is bidirectional search algorithm?
Sorting algorithms and time complexity of various algorithms.
There are numbers from 1 to n, which are inverted such that it results in numbers from n to 1. If only two consecutive numbers are stampled at a time and are inverted, how many moves are required?
can anyone help me with some suggestions and improvemnts for sage line 50?
Which algorithm inverts a complete resolution strategy?
what is software cycle?give a diagramatic representation
Consider the following algorithm: for ( i = 2 ; i <= n ; i++) { for ( j = 0 ; j <= n) { cout << i << j ; j = j + floor(n/4) ; } } (a) What is the output when n = 4 (b) What is the time complexity T(n). You may assume that n is divisible 4.