Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Define Routing Algorithm?

999


What do you mean by overfitting and underfitting algorithms?

966


What are the complexities of sorting algorithms and how can this complexity be calculated?

961


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).

905


What is depth-first search algorithm?

906


Explain me what's your favorite algorithm, and can you explain it to me in less than a minute?

1058


Write an algorithm to traverse a knight covering all the squares on a chessboard starting at a particular point.

935


What is iterative deepening depth-first search algorithm?

910


What is bidirectional search algorithm?

1094


What is the uniform cost search algorithm?

904


What is the breadth-first search algorithm?

880


A* algorithm is based on which search method?

1527


Tell us how will you know which machine learning algorithm to choose for your classification problem?

897


What is the bidirectional search algorithm?

935


What is breath-first search algorithm?

900