Presentation is loading. Please wait.

Presentation is loading. Please wait.

5.3 Sorting Techniques. Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key.

Similar presentations


Presentation on theme: "5.3 Sorting Techniques. Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key."— Presentation transcript:

1 5.3 Sorting Techniques

2 Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key is the first key by which data in a file is sorted, e.g., area code for a mailing list Secondary key is the second key by which data in a file is sorted within the primary key order. E.g., a mailing list sorted by area code can again be sorted in alphabetical order of name within each area code.

3 Sorting Techniques Sorting techniques include – 1. Selection Exchange Sort, bubble Sort, Quick Sort, Shell Sort and Heap Sort Best sorting techniques are determined by the number of comparisons and switches that take place for a file of n records in a specific order. Memory space is also a consideration when considering a sorting technique.

4 The Selection Exchange Sort To sort n records Think of 2 sublists within n records – 1. List of sorted part (S) – 2. List of unsorted part (U) Initially number of elements in S=0 and number of elements in U = n 1. Find the smallest element in unsort part and switch it with the first element of the array.

5 The Selection Exchange Sort 2. While number of elements in (U) > 1 – Find the smallest element in Unsorted part and switch with first element of Unsorted part. [Once switched this first element of U becomes the last element of S]

6 The Selection Exchange Sort

7

8 Practice Create a 1D 6 element array that is populated by user, sort this array in a Sort_Array function using selection sort algorithm, then print the new sorted array to screen in the main function.


Download ppt "5.3 Sorting Techniques. Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key."

Similar presentations


Ads by Google