Showing posts with label data structure. Show all posts
Showing posts with label data structure. Show all posts

Monday, May 19, 2014

Technique: Selection Sort Animation

    Selection sort step by step animation, for the programming beginners to get a better understanding of selection sort algorithm.(Click snail button to start animation and click it again to go back to the first page)


Cost: O(n^2)
Worst case: O(n^2)
Best case: O(n)

Selection sort code in C++:

void SelectionSort(int a[],int size)
{
       for(int i=0;i<size-1;i++)
       {
               int min=i;
               for(int j=i+1;j<size;j++)
               {
                      if(a[j]<a[min])
                      {
                             min=j;
                      }
                }

                if (min > i)
                      swap(a[i],a[min]);
        }
}

int main()
{
   int a[]={25,49,8,25,21,16,32};
   SelectionSort(a,7);

}


More technique animations:

Heap Sort
Binary Search
Merge Sort
Quick Sort
Bubble Sort

Wednesday, April 2, 2014

Technique: Bubble Sort Animation

    Bubble sort step by step animation, for the programming beginners to get a better understanding of bubble sort algorithm.(Click snail button to start animation and click it again to go back to the first page)



Cost: O(n^2)
Worst case: O(n^2)
Best case: O(n)

Bubble sort code in C++:

void BubbleSort(int a[],int n)
{
    for(int i=1; i<n; i++
    {
                  for(int j=0; j<n-i; j++)
                  {
                      if(a[j] > a[j+1])
                       {
                         int temp;
                               temp = a[j];
                               a[j] = a[j+1];
                                    a[j+1] = temp;
                      }
                  }
    }
}

int main()
{
    int a[]={25,49,8,25,21,16,32};
    BubbleSort(a,7);

}


More technique animations:

Heap Sort
Binary Search
Merge Sort
Quick Sort
Selection Sort