Science Fair Projects Ideas - Double bubble sort

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Double bubble sort

Double bubble sort is a sorting algorithm similar to insertion sort. It works relatively well on data that is already almost sorted, and can outperform quicksort in such conditions. If the data is already in order, only a single pass will be made through the list.

The essential difference from insertion sort is that the double bubble sort swaps adjacent pairs, while the insertion sort takes each value from the array and then puts it in place only once all elements ranking above it have been moved forward, this does decrease performance. However by using the xor swap algorithm, double bubble sort uses one fewer variable than insertion sort.

void doublebubbleSort(int *array, int length)
{
   int i, j;

   for(i = 0; i < length-1; i++)
   {
      if(array[i] > array[i+1]) /* compare neighboring elements */
      {
         for(j = i; j>=0 && (array[j] > array[j+1]); j--)
         {
             array[j] ^= array[j+1]; // Use Xor swap algorithm to increase efficiency
             array[j+1] ^= array[j];
             array[j] ^= array[j+1];
         }
      }
   }
}

Double bubble sort is also used as a synonym for cocktail sort.

09-23-2007 01:00:40
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice