Monday, March 1, 2010

Art of computer programming -Sorting #5

Improvements that can be made on bubble sort

There are basically 2 improvements that you can make on bubble sort.

One, you can eliminate certain comparisons. For example if 2 elements i and j in an array don't change their respective positions in 2 simultaneous passes during a bubble sort. Then it means that the values are in their final positions. Such elements can be left alone when comparing.

Another distant possibility is that we can shift the base of the array left or right when we want to shift a position to left or right. This will help us in doing lesser number of comparisons. But whatever we do, it does not make the bubble sort any better than a selection sort or an insertion sort.

So layman tells you to quit using the bubble sort for practical purposes.

Thanking you,
Layman

7 comments:

  1. 忙碌的一天終於過了,來看看文章轉換心情,也幫你加個油哦~........................................

    ReplyDelete
  2. nice one da.... keep writing

    ReplyDelete
  3. Dear sir,
    I want to develop an application where i have to interact with a GSM Modem and require to write AT Commands on the modem via the com port from a C++ program..
    I am using VC++..
    The application which i am trying to develop is described below..
    I am trying to find the shortest path between two places using Dijkstra's algorithm...
    Here,the inputs (source and destination) will be given by any user through a mobile phone..ie the user will send an sms which comprises the information about source and destination...
    This information is actually sent to a modem which is connected to a system using a serial port...The input via modem should be provided to the program which runs the Dijkstra's algorithm and the program should return the output(ie the shortest path) to the modem,which in turn should send it to the appropriate user who had requested for the service...
    I am completely done with the software part..
    But I am new to the field of serial communication and VC++...
    I see one of your posts while searching in the internet and got your mail id...
    I am in urgent need of the help....Please guide me regarding the further proceedings...

    Regards,
    Anoop.

    ReplyDelete
  4. Please send me a mail on ma email..... layman

    ReplyDelete