Thread: What is difference between Bubble,selection & insertion sort?

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    54

    What is difference between Bubble,selection & insertion sort?

    What is difference between Bubble sort, selection & insertion sort?
    Can anyone allaborate without C code?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    If you want an understanding of algorithms "without code", imagine the situation as a game. Someone hands you a stack of random cards and the objective is to arrange the cards in order. But you have certain rules. All the cards are face-down. You can only uncover a certain number of cards at a time, remembering a card uses some of your memory, and each time you move or exchange cards, you have to use one move. Sorting algorithms (or in fact any algorithm) could be seen as strategies to finish the game. Hopefully one would hope that the strategy is one which uses as few moves as possible or by using the least amount of memory as possible.

    The algorithms you named are all strategies to solve the sorting problem. Try to find a good description of the algorithm as "pseudocode" and then read and understand how it works without regarding to a programming language. The differences usually come down to a difference in time complexity (how "fast" it is) or space complexity (how much memory it uses).

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Check some small videos I used to watch when first meeting these algorithms!



    If you want to see some code of bubblesort, you can check here.
    (Notice that there you will find three implementations of bubblesort, so if you haven't understand the naive implementation, then you might want to click this link after you do understand it).
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-03-2011, 02:05 PM
  2. Replies: 1
    Last Post: 01-26-2010, 09:02 AM
  3. Insertion and selection sort
    By Dashing Boy in forum C Programming
    Replies: 4
    Last Post: 08-29-2006, 04:42 PM
  4. Bubble Sort / selection problem
    By Drew in forum C++ Programming
    Replies: 7
    Last Post: 08-26-2003, 03:23 PM