GithubHelp home page GithubHelp logo

bubblesort's Introduction

Bubble Sort

Bubble Sort works by comparing two numbers at a time: the current number in a list and the one that follows it. If the second number is smaller than the first, it swaps their positions before going to the next number. In this way, lower numbers are always moving to the left and higher numbers to the right. The sorting starts again at the beginning of the list, and continues until the entire list is checked with no swaps.

Pseudo code

  1. Start with the first number in the list.
  2. If the next number in the list is lower than the current number, swap their positions.
  3. Go to the next number and repeat step 2 until the end of the list.
  4. If there have been any swaps since the beginning of the list, go back to step 1.

Best case

The best case scenario for this algorithm is a list that is already in the sorted order. The algorithm will only have to traverse the list once. Performance won't be great, but it won't be awful, and will degrade in a linear fashion.

Worst case

The worst case scenario for this algorithm is a list in reverse sorted order. The algorithm will have to traverse the entire list once for each list item. Performance will be lousy, and degrade quickly with a larger list.

bubblesort's People

Contributors

panicboy avatar

Watchers

James Cloos 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.