 Welcome to this video lecture. In the past video lectures we have seen how to sort data using bubble sort, using selection sort, insertion sort. The last video we saw and understood merge sort and in today's lecture we are going to see how to use quick sort and understand the algorithm. So by the end of this session you will understand the working of quick sort algorithm, how quick sort algorithm method sorts n elements in the correct sorted order. So these are the prerequisites I strongly encourage you that you go through the videos of arrays and loops and also know that how swapping of two elements which are in an array is done in C. Talking about quick sort, this algorithm is one of the fastest algorithms available to sort given data. In quick sort an element called as pivot is selected and usually this is the element which is available in the first position. So based on the position and the value of this pivot element, the array that is divided into sub arrays and sub sub arrays so as the elements to the left of the pivot are less in value than the pivot element itself and similarly the elements at the right of the pivot element are greater than the pivot element. So this partitioning is done based on the pivot element and once the partition is over then the pivot element is situated at its sorted position. The elements are scanned, they are compared and swapped if required in order so that the pivot element lies in its sorted position. Next element becomes the pivot that is the next element which is at the first position it becomes the pivot and the same process continues till the whole array is sorted. There are some variations in the use and in the implementation of quick sort. Many a times the last element in the array is used as the pivot element, a random element from the array is selected as the pivot element but here we are going to select the first element as the pivot element. So this is the pseudo code where the pivot position is returned by the subroutine partition and the same algorithm quick sort is recursively called over the left sub array and the right sub array. So this is the pseudo code of the partition subroutine. The pivot element is the first element of the array and there is this index j which is one position ahead of the start element and it goes till the end of the array. So here if the element at the jth index is less than the element of at the pivot element or if the pivot element is greater than the element at the jth index we swap these two elements at the ith and the jth index respectively and increment the i index by one. Here the whole array is scanned, we swap the elements at the start index and the i minus one index where i minus one is the position of the pivot element. Now we shall see the simulation of quick sort. Now this is the visualalgo.net platform where the simulation of many algorithms and almost all the sorting algorithms is given so that we can get our understanding clear. So here I am going to create an random ordered array of size 5 so that we can quickly see how the quick sort algorithm works. So here the array is in the random order element 8 is selected as the pivot element and since there is no element greater than 8 we are scanning to the right and now 8 is swapped and it finds its final position in the array. Now you can see that the partition is based on the pivot element where since 8 was the first element in the array so all the elements to the left of 8 are in the same partition because they are all less in value than 8. So the next pivot element is 1, 5 is a value greater than 1, so is 3 and 2 also. So it is swapped with the same position and 1 finds its final value in the array which is the first position. Now all the elements to the right are greater than 1. So 5 becomes the next pivot element 3 is less in value than 5 so is 2. So 5 is swapped with the element at the n minus 1 position and this is done because we come to the last step and in last step the pivot element is put in its final position. Now the next pivot is value 2, 3 is already greater so 2 finds its final place in the array and it is sorted and the next element 3 becomes the pivot and since it is the only element we see that the array is in its sorted form. This is how quick sort recursively calls itself based on the position of the pivot and then it arranges the elements in the partition. Right now it is time for a question. The question is quick sort follows which of the following design methodology. Pause the video and answer the question. This quick sort splits the array based on the partition element. It is known that quick sort follows divide and conquer methodology just like the merge sort. These are the references. Thank you for watching.