LEARNING JOURNAL

I created this learning journal to practice writting and to help me learn by writting everything down. Source code here

1/30/2024

Quick sort

This is the solution for the Sort an Array problem using QuickSort.

Basically, what QuickSort does is choose a random element in the array, move all smaller element to the left and all bigger elements to the right, then put that element in the middle. Now, we know that the random element is in its place. Continue to do it for the left and then the right portion of the array util you reach a sub-array of 1.

The job is done in the partition function. We use 2 pointers, one start from the left and the other starts from the right. On the way moving toward each other, when they see some elements that are not in their right sides of the array, swap them.

However, I still don't understand why the pre-decrement and pre-increment play the crucial role in the speed of the algorithm though.