Bubble Sort 2- Pseudocode and Enhancements

Поділитися
Вставка
  • Опубліковано 26 січ 2025

КОМЕНТАРІ • 34

  • @iramkhan9748
    @iramkhan9748 4 роки тому +2

    solid work. i rewatched this several times for my vb programming final! keep it up!

  • @saeedmirzaei1
    @saeedmirzaei1 4 роки тому +2

    Very nice explanation. Thank you so much.

  • @vistchr
    @vistchr 3 роки тому +1

    I've warched tons of videos explaining how bubble Sort pseudo code works but still can't get it - help

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 роки тому +1

      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

  • @flacko3707
    @flacko3707 8 років тому

    hopfully the next one comes out soon because i really want to see it

  • @akashvishal7640
    @akashvishal7640 9 місяців тому

    Sir how do you display the steps in bubble sort in VB

    • @ComputerScienceLessons
      @ComputerScienceLessons  8 місяців тому

      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

  • @ylangylang1088
    @ylangylang1088 3 роки тому +1

    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?

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 роки тому

      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/

    • @ylangylang1088
      @ylangylang1088 3 роки тому

      Computer Science yes ,but a fourth scan won't mess anything up right

    • @ComputerScienceLessons
      @ComputerScienceLessons  3 роки тому +1

      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.

    • @ylangylang1088
      @ylangylang1088 3 роки тому

      Computer Science Thanks a lot

  • @SiteBizzona
    @SiteBizzona 5 років тому

    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));

  • @estebanfigueroafalla5949
    @estebanfigueroafalla5949 7 років тому

    Hi, a question, when i have the numbers, where i should write them in the pseudocode. Thanks

    • @ComputerScienceLessons
      @ComputerScienceLessons  7 років тому +1

      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

  • @munyafiction
    @munyafiction 8 років тому +1

    thanks for the videos!

  • @antonov621
    @antonov621 4 роки тому +1

    excellent video and accent

  • @kur0sh1
    @kur0sh1 5 років тому

    you could just use a conditional loop for the the number of passes it makes

  • @tobi3497
    @tobi3497 8 років тому

    Didn't you upload this, a few days ago, as a single video?

    • @ComputerScienceLessons
      @ComputerScienceLessons  8 років тому +3

      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.

    • @tobi3497
      @tobi3497 8 років тому +1

      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.

  • @monalisaha1573
    @monalisaha1573 7 років тому +1

    How will we find the median through bubble sort?

  • @awildhagird662
    @awildhagird662 8 років тому

    Awesome Vid

  • @tylertimes3134
    @tylertimes3134 6 місяців тому +1

    teehe