affiliate marketing
Showing posts with label sorting in data structure. Show all posts
Showing posts with label sorting in data structure. Show all posts

Saturday, 10 December 2011

Bubble sort


Bubble sort
            Let a be an array of n numbers. Our aim is to sort the numbers in the array in ascending order. The principle is to scan the array sequentially n-1 times and in each scan do the following steps.
Scan – 1
i)                    Take the first element and compare it with the second element. If it is small don’t interchange; or else interchange the two elements.
ii)                  Then compare the second element with the third element. If it is small don’t interchange; or else interchange the two elements.
iii)                This process is continued till (n-1)th element is compared with the nth element.
iv)                At the end of the first scan, the highest element comes to the nth position.
Scan – 2

SORTING


1 Sorting
General Concepts
            A file is an ordered collection of items.Each item in the file is called a record. The records are named as r[1], r[2],…..r[n], where n is the size of the file.
            A key is associated with each record r[i] and through this key only we can identify the records in the file.