Giter Club home page Giter Club logo

bubble-sort's Introduction

bubble-sort

Bubble sort

Sorts an array of numbers into ascending order by comparing consecutive elements in the array.

For instance: bubble_sort([1, 4, 2, 4, 1]) first looks at the pair 1, 4. In this case 4 is already greater than 1 and no swapping is needed. The second pair is 4, 2. Here, 2 is less than 4 and they swap places. Now when 2 and 4 are swapped, the next pair is 4, 4. No swapping is needed here because they are equal. The last pair 4, 1 is swapped, which produces the array [1, 2, 4, 1, 4] after the first pass. This process is repeated until the entire array is in ascending order.

Note that the right-most element is always in its correct place after the first pass. And generally, after k passes, the k right-most elements are correctly ordered. This means that after k passes in an array of n elements, only the first n-k elements need to be sorted.

bubble-sort's People

Contributors

lbackman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.