Computer Applications
Given an array 12, 3, 8, 5. What will be array like after two passes of bubble sort?
- 12, 3, 8, 5
- 3, 8, 12, 5
- 3, 5, 8, 12
- 12, 3, 5, 8
Java Arrays
5 Likes
Answer
3, 8, 12, 5
Reason — The basic idea of bubble sort is to move the largest element to the highest index position in the array. To attain this, two adjacent elements are compared repeatedly and exchanged if they are not in correct order.
In the first pass, adjacent elements (12,3) will be compared and swapped. The array will look like this after the first pass:
3, 12, 8, 5
In the second pass, adjacent elements (12,8) will be compared and swapped. The array will look like this after the second pass:
3, 8, 12, 5
Answered By
3 Likes
Related Questions
Given that
int z[ ][ ] = {{2, 6, 5}, {8, 3, 9}};What will be value of z[1][0] and z[0][2] ?- 2 and 9
- 8 and 5
- 2 and 5
- 6 and 3
Given array 12, 3, 8, 5. What will be array like after two passes of selection sort ?
- 12, 3, 8, 5
- 3, 5, 8, 12
- 3, 8, 5, 12
- 3, 5, 12, 8
An array
18, 13, 2, 9, 5
is
13, 2, 9, 18, 5
after three passes. Which sorting technique is applied on it?What do you understand by an array ? What is the significance of arrays ?