0
0
What is the maximum number of comparison required to sort an array of 5 elements in bubble sort?
What is the maximum number of comparison required to sort an array of 5 elements in bubble sort?
1). 5
2). 3
3). 10
4). 25
1). 5
2). 3
3). 10
4). 25
This Question has 1 answers.
Bubble sort algorithm requires a pair of nested loops. The outer loop must iterate once for each element for the given elements i.e. n times while the inner loop iterates n times for first iteration, n - 1 time for second iteration, n - 2 times for the third iteration and this process continues.
Total number of comparison = (n - 1) + (n - 2) + (n - 3) + … = n(n - 1)/2
= 5(4)/2
= 20/2
= 10Similar Questions
- In an alloy, zinc and copper are in the ratio 1 : 2. In the second alloy, the same elements are in the ratio 2 : 3. If these two alloys be mixed to form a new alloy in which two elements are in the ratio 5:8, the ratio of these two alloys in the new allow
- Two types of rice (type 1 and type 2) were mixed in the respective ratio of 1 : 3. The mixture was then sold @ 75.60 per kg to gain a profit of 20%. If the price of type 1 rice is Rs. 75 per kg, what is the price of type 2 price per kg?
- In a hotel, the rooms are numbered from 101 to 130 on the first floor, 221 to 260 on the second floor and 306 to 345 on the third floor. In the month of June this year, the room occupancy was 60% on the first floor, 40% on the second floor and 75% on the
- A person ordered 4 shirts of brand A and some shirts of brand B. The price of one shirt of brand A was twice that of brand B. When the order was executed, it was found that the numbers of the two brands has been interchanged . This increased the bill by 4
- Direction: Read the following information carefully and answer the questions that follow: P, V, X, A, D, I, K and UÂ set out for trip for different number of days such as 2, 8, 11, 5, 6, 4, 7 and 3, they go to the trip in the same order but the order of n