answersLogoWhite

0


Best Answer

bubblesort(int[] unsortedList){ 1)for(int i=1; iunsortedList[j]){ 4) int temp = unsortedList[i]; 5) unsortedList[i] = unsortedList[j]; 6) unsortedList[j] = temp; } } } return unsortedList } Explanation: 1: take each element in unsortedList, one at a time, and call the variable in it i 2:for each i, take each element further down the list one at a time and call this j 3:compare i to j, if i is grater than j, then j should go before anything i should go before so swap them. j will then be the new i, but is still in the correct place in the list because i was up until it saw j. i will be put back where it shopuld go next time round. Example: 1 4 3 7 5 6 I=14 3 7 5 6 I=4>j=3 1 3 4 7 5 6 I=34 7 5 6 I=47 5 6 I=7>j=5 1 3 4 5 7 6 I= 5>j=6 1 3 4 5 7 6 I=7>j=6 1 3 4 5 6 7 return 1 3 4 5 6 7 bubblesort(int[] unsortedList){ 1)for(int i=1; iunsortedList[j]){ 4) int temp = unsortedList[i]; 5) unsortedList[i] = unsortedList[j]; 6) unsortedList[j] = temp; } } } return unsortedList } Explanation: 1: take each element in unsortedList, one at a time, and call the variable in it i 2:for each i, take each element further down the list one at a time and call this j 3:compare i to j, if i is grater than j, then j should go before anything i should go before so swap them. j will then be the new i, but is still in the correct place in the list because i was up until it saw j. i will be put back where it shopuld go next time round. Example: 1 4 3 7 5 6 I=14 3 7 5 6 I=4>j=3 1 3 4 7 5 6 I=34 7 5 6 I=47 5 6 I=7>j=5 1 3 4 5 7 6 I= 5>j=6 1 3 4 5 7 6 I=7>j=6 1 3 4 5 6 7 return 1 3 4 5 6 7

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: About bubble sort
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is another name for bubble sort?

Bubble sort is also known as sinking sort.


Is bubble sort a stable sorting algorithm?

Yes, bubble sort is a stable sorting algorithm.


Which sorting algorithm is more efficient for small datasets: bubble sort or selection sort?

Selection sort is more efficient for small datasets compared to bubble sort.


Who invented the bubble sort?

ramesh


Bubble sort Extra or in space?

Bubble sort is an "in place" algorithm. Other than a temporary "switch" variable, no extra space is required.


Can you draw a flow chart for bubble sort?

no


What is bubble sort and explain with examples?

bubbles


What are some sorting rules for math?

Binary sort and bubble sort are two.


How do you sort the given contents of an array?

You would sort the given elements of an array by a bubble sort or heap sort code!!


What is the running time of bubble sort algorithm?

The running time of the bubble sort algorithm is O(n2), where n is the number of elements in the array being sorted.


What is the running time of the bubble sort algorithm?

The running time of the bubble sort algorithm is O(n2), where n is the number of elements in the array being sorted.


What are the advantages for bubble sort?

Bubble sort has no practical applications other than that it is often cited as an example of how not to write an algorithm. Insert sort is the best algorithm for sorting small lists of items and is often used in conjunction with quick sort to sort larger lists. Like insert sort, bubble sort is simple to implement and is a stable sort (equal items remain in the same order they were input). However, insert sort uses copy or move operations rather than swaps (which is actually three operations per swap) and is therefore quicker. The only time a bubble sort will work quicker than insert sort is when the array is already sorted, which renders the entire algorithm redundant. A modified algorithm that specifically tests if an array is sorted or not would be more efficient than a single-pass bubble sort.