retagged by
4,739 views
2 votes
2 votes
A machine took 200 sec to sort 200 names,using bubble sort.In 800 sec,it can approximately sort ?
a. 400 names b. 800 names c. 750 names d. 850 names
retagged by

3 Answers

Best answer
5 votes
5 votes

Using Bubble sort total number of comparisons $\frac{n(n-1)}{2}$ or $O(n^{2})$

So for sorting 200 names bubble sort makes $200^{2}$ comparisons in worst case.To sort 200 names bubble sort is taking 200 sec or we can say 40000 comparisons takes 200 sec.

Now we have compute how many names will sort in 800 sec.

So $n^{2}=\frac{40000\times 800}{200}$

So $n$=400 names will sort in 800 sec.

 


Alternatively

For 200 names =200*199/2

                        =19900 comparison

So 19000 c=200 sec

$\frac{n(n-1)}{2}$=800 sec

$\frac{n(n-1)}{2}$=79600

So $n$=400

selected by
1 votes
1 votes

To Find solution these kind of quetion u have to know What is the time complexity of given algorithm 

like in above quetion Bubble  sort

Best case = O(n2) without modified

Worst case = O(n2)

Now take quetion If he say how many time to sort 800 names.

200 sec to sort 200 names using bubble sort.

Bubble sort take for n names = O(n2

here take 200 = 200sec

but in actual it take O(2002)= 40000sec

now simple math apply inplace of 40000/200 = 200 it take 200 sec

for 800 bubble sort actualy take o(8002)= 160000 sec

But like above divide ans by 200 so 640000/200= 3200sec

 

 

but he is asking for how many name sort in 800 sec ..

so to in 200 sec= 200 name 

but actualy it want 40000sec

in quetion 1 sec= 1name

wat is relation b/w program and actual algorithm time complexity

so 1 sec = 200/40000= 1/200 name 

so  in 800 sec= O(n2)

since 800 sec= O(n2)/200

= 160000= O(n2)

take log both side

u get n= 400

edited by
0 votes
0 votes

we know the time complexity of bubble sort is O(n2).

where n=no of elemnts given

A/Q

200 elemnts are required to be sorted in 200sec

i.e 200*200(40000) comparision are req to sort in 200 sec

1 comparision is requies 1/200sec.........................(A)

let there are kcomparsion are req for k elemnt that can be sorted in 800 sec

therefore,

from eqation A

k2  *1/200=800

on soving we get k=400  ans  

Related questions

0 votes
0 votes
2 answers
2
_Madhuri asked Oct 9, 2021
668 views
The complexity of comparison based sorting algorithm is (nlogn) .How?
0 votes
0 votes
1 answer
3
Smishra95 asked Sep 28, 2018
2,072 views
Given an array where numbers are in range from 1 to n6 , which sorting algorithm can beused to sort these number in linear time?A. Not possible to sort in linear timeB: C...
0 votes
0 votes
0 answers
4