24.Bubble sort is also called
a.Exchange sort b.Sinking sort c.Both D.none
Ans:c
25. Which of the following correctly describe(s) the bubble sort algorithm?
a. public void bubblesort(int[ ] data)
{ int temp;
int i, j ;
for (i = 1; i < data.length; i++)
{ temp = data[i] ;
for (j = i; j>0 temp < data[j – 1]; j--)
data[j] = data[j – 1] ;
data[j] = temp ; } }
b. public void bubblesort(object[ ] data)
{ int i, j, least
for ( i = 0; i< data.length; j++)
if (((comparable[j]).compareTo(data[least])<0)
least = j ;
swap (data, least, i); }
c. public void bubblesort(object[ ] data)
{ int i, j
for (i = 0; i < data.length-1; i++)
for ( j = data.length-1; j>i; --j )
if (((comparable) data[j]).compareTo(data[j-1] <0)
swap (data, j, j-1) }
d. void bubblesort(object[ ] data)
{ for (int i = data.length/2 –1;i)> = 0; --i)
movedown(data. i, data.length – 1) ;
for (int i = data.length –1; i > = 1 ;--i)
{ swap(data, 0, i)
movedown(data, 0, i-1) ; } }
Ans. e
26.The number of nested loops in a bubble sort algorithm
a.1 b.2 c.3 d.4
Ans:b
27. Let A be a list of n numbers. Sorting A refers to the operation of re-arranging the elements of A so that they are in increasing order.
If A= { 32, 51, 27, 85, 66, 23, 13, 5} and method of sorting is bubble sort, Which is/are the correct intermediate output values during the process of sorting.
a.23, 13, 5, 27, 32, 51, 66, 85
b.27, 32, 23, 13 ,5, 51 66, 85
c.32, 27, 51, 66, 23, 13, 5, 85
d.32, 51, 85, 27, 66, 23, 13, 5
Ans:a,c,d,
28. What is the output of bubble sort after the 1st pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15
a. 48 25 37 12 57 86 33 92 23 15
b. 25 48 37 12 57 86 33 23 15 92
c.12 25 33 37 48 57 86 92 23 15
d. 25 57 37 48 12 92 33 86 23 15
Ans:b
29. What is the output of bubble sort after the 2nd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15
a. 48 25 37 12 57 86 33 92 23 15
b. 25 48 37 12 57 86 33 23 15 92
c. 25 37 12 48 57 33 23 15 86 92
d. 25 57 37 48 12 92 33 86 23 15
Ans:c
30. What is the output of bubble sort after the 3rd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15
a. 48 25 37 12 57 86 33 92 23 15
b. 25 48 37 12 57 86 33 23 15 92
c. 25 37 12 48 57 33 23 15 86 92
d. 25 37 12 48 33 23 15 57 86 92
Ans:d
31. What is the output of bubble sort after the 4th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15
a. 48 25 37 12 57 86 33 92 23 15
b. 25 48 37 12 57 86 33 23 15 92
c. 25 37 12 48 57 33 23 15 86 92
d. 25 12 37 33 23 15 48 57 86 92
Ans:d
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment