You should make sure you understand the method (the algorithm) before you look at any pseudocode or implementation code. If you haven't already done so, watch the first 3 minutes and 28 seconds of my introduction video. ua-cam.com/video/gaC4MKqn41g/v-deo.html Then, get some playing cards, or write numbers 1 to 10 on little squares of paper, lay them out in front of you in descending order, and sort them into ascending order using the algorithm. Do it again, but put them in a random order to start with. Do it several times until you can apply the the algorithm easily. - Then you can think about the code :)KD
If you are using visual studio, you can set a break point and step through the code as it runs. This video shows how to use break points ua-cam.com/video/EceKLMxzE_8/v-deo.html
No. An array of 4 items needs to be scanned 3 times (3 passes) because that is all you need to do to ensure the list is sorted. Take a look at this diagram www.computersciencebytes.com/sorting-algorithms/bubble-sort/
No - but you will be scanning a list that is already sorted. You can scan it a million times if you like and it will make no difference. In my video about enhancements, we add some logic to check if there have been any swaps during each scan; if not, the data must now be in order so we stop scanning. This means that if you bubble sort a list that is already sorted (using this enhancement), it will scan it only once.
It doesn't necessary to use two FOR, We can also use onle while operator. For example on PHP code: $data = [4,2,7,1,9,0, 12,56,3]; function bubleSort($data) { $cnt = count($data); $i = 0; while ($i < $cnt -1) { if ($data[$i] > $data[$i+1]) { $temp = $data[$i]; $data[$i] = $data[$i+1]; $data[$i+1] = $temp; $i = 0; } else { $i +=1; } } return $data; } print_r(bubleSort($data));
You will need to initialise the array before the sorting routine begins. How you do this in reality depends on the programming language you are using. In pseudocode, you could say: ArrayToSort(0) = 5 ArrayToSort(1) = 7 ArrayToSort(2) = 12 ArrayToSort(3) = 4 ArrayToSort(4) = 8 etc. Or you could you prompt a user for input using a loop like this For i = 0 to ubound(ArrayToSort) ArrayToSort(i) = new data item Next i Take a look at my playlist on array variables. ua-cam.com/play/PLTd6ceoshpreU16T3ZBdwiSyxqT50UPxm.html
I did Tobi. I found a small error in the pseudocode, which might have confused some people, so I decided to fix it. I then though it would be better to split it into two videos while I was at it. I think some people prefer shorter videos, and I figured the algorithm on its own (without the pseudocode) would be better for a younger audience. To be honest, I was originally working on a video about Big O notation, and I wanted to include some stuff about the of the bubble sort in that. I then got side tracked onto the bubble sort.
Also, would you say your videos are suitable for the A-level specification? I haven't taken a look through them yet, but intend to set aside some time to go through the entire series, to consolidate knowledge before paper practice.
solid work. i rewatched this several times for my vb programming final! keep it up!
Very nice explanation. Thank you so much.
You are very welcome. Thanks for the comment. :)KD
I've warched tons of videos explaining how bubble Sort pseudo code works but still can't get it - help
You should make sure you understand the method (the algorithm) before you look at any pseudocode or implementation code. If you haven't already done so, watch the first 3 minutes and 28 seconds of my introduction video. ua-cam.com/video/gaC4MKqn41g/v-deo.html Then, get some playing cards, or write numbers 1 to 10 on little squares of paper, lay them out in front of you in descending order, and sort them into ascending order using the algorithm. Do it again, but put them in a random order to start with. Do it several times until you can apply the the algorithm easily. - Then you can think about the code :)KD
hopfully the next one comes out soon because i really want to see it
Sir how do you display the steps in bubble sort in VB
If you are using visual studio, you can set a break point and step through the code as it runs. This video shows how to use break points ua-cam.com/video/EceKLMxzE_8/v-deo.html
The reason we're scanning the array one time less than the number of items in the array is only for the sake of optimization, right?
No. An array of 4 items needs to be scanned 3 times (3 passes) because that is all you need to do to ensure the list is sorted. Take a look at this diagram www.computersciencebytes.com/sorting-algorithms/bubble-sort/
Computer Science yes ,but a fourth scan won't mess anything up right
No - but you will be scanning a list that is already sorted. You can scan it a million times if you like and it will make no difference. In my video about enhancements, we add some logic to check if there have been any swaps during each scan; if not, the data must now be in order so we stop scanning. This means that if you bubble sort a list that is already sorted (using this enhancement), it will scan it only once.
Computer Science Thanks a lot
It doesn't necessary to use two FOR, We can also use onle while operator. For example on PHP code:
$data = [4,2,7,1,9,0, 12,56,3];
function bubleSort($data) {
$cnt = count($data);
$i = 0;
while ($i < $cnt -1) {
if ($data[$i] > $data[$i+1]) {
$temp = $data[$i];
$data[$i] = $data[$i+1];
$data[$i+1] = $temp;
$i = 0;
} else {
$i +=1;
}
}
return $data;
}
print_r(bubleSort($data));
Hi, a question, when i have the numbers, where i should write them in the pseudocode. Thanks
You will need to initialise the array before the sorting routine begins. How you do this in reality depends on the programming language you are using. In pseudocode, you could say:
ArrayToSort(0) = 5
ArrayToSort(1) = 7
ArrayToSort(2) = 12
ArrayToSort(3) = 4
ArrayToSort(4) = 8
etc.
Or you could you prompt a user for input using a loop like this
For i = 0 to ubound(ArrayToSort)
ArrayToSort(i) = new data item
Next i
Take a look at my playlist on array variables. ua-cam.com/play/PLTd6ceoshpreU16T3ZBdwiSyxqT50UPxm.html
thanks for the videos!
You're very welcome Eternal Mist.
excellent video and accent
You're welcome. TY :)KD
you could just use a conditional loop for the the number of passes it makes
Didn't you upload this, a few days ago, as a single video?
I did Tobi. I found a small error in the pseudocode, which might have confused some people, so I decided to fix it. I then though it would be better to split it into two videos while I was at it. I think some people prefer shorter videos, and I figured the algorithm on its own (without the pseudocode) would be better for a younger audience. To be honest, I was originally working on a video about Big O notation, and I wanted to include some stuff about the of the bubble sort in that. I then got side tracked onto the bubble sort.
Also, would you say your videos are suitable for the A-level specification? I haven't taken a look through them yet, but intend to set aside some time to go through the entire series, to consolidate knowledge before paper practice.
How will we find the median through bubble sort?
Awesome Vid
teehe
tyler you look hot
tank you i know
can i get your gram?
not oan sos
whynot