In this article, I discuss sorting in the Pascal programming language. Sorting is a very useful technique that is used vastly in various programs. This is a programming technique that is used to sort a list of pre-stored data list in a descending or ascending order according to a preset criterion.
There exist various sorting methods in Pascal programming that are used according to a given situation. All of these sorting methods are compared to one another using a time unit measure known as the big-O notation. This technique is for measuring the efficiency of an algorithm that performs a particular function over a collection of items of size p. Take an example, the big-O complexity of both the Bubble sort and Insertion Sort is O (p2). Although both do have the same time complexity, Insertion Sort is slower.
There are many useful sorting methods. Here we will discuss just a few sorting methods in Pascal Programming. The Bubble Sort algorithm is very simple though also an inefficient sorting algorithm. It is not usually the best option to use. This is because its performance at sorting a list of items is extremely slow. In Pascal programming, it is best at sorting a small list of items, but not for large items. For the Bubble sort, the sorting time complexity is O (p2).
Another sorting method in Pascal programming is the Insertion Sort algorithm. This one is a bit more efficient algorithm than the Bubble Sort algorithm. As its name implies, the insertion sort algorithm does insert an unsorted item in an item list that is already sorted. This makes one think of the use of two separated arrays – one sorted and the other unsorted. However, to save space one may use the same array and use a pointer to separate the unsorted and sorted elements of the list.
In this algorithm, the sorting time complexity is O (p2). Although this is the same as that of the Bubble Sort’s, the Insertion Sort algorithm is twice more efficient and inefficient for large lists.
Another algorithm in Pascal programming is the QuickSort algorithm. This algorithm does seem pretty fast in performance, though it’s not easy to implement although getting the gist of how the Quicksort algorithm works is not that hard.
This algorithm does use recursion extensively, so one should ensure he is quite familiar with recursion, and he has used it a lot before he tries to understand this algorithm. The quicksort does work by using a “pivot”. This is an index pointer just like the ones that are used in previous sorting algorithms. Its purpose is to divide the list into two halves, one having elements greater than the pivot while the other having elements smaller than the pivot. The pivot is mostly chosen to be the left-most element of the list. However, it is not necessary and one may decide to choose any random element from the list to be his pivot.