human
Can you provide a code to hoare 's vs Lomuto partition scheme in QuickSort and the other steps required given the following:
Hoare 's vs Lomuto partition scheme in QuickSort | This function takes first element as pivot , and places all the elements smaller than the pivot on the left side and all the elements greater than the pivot on the right side . It returns the index of the last element on the smaller side.
Find leftmost element greater than or equal to pivot.
Find rightmost element smaller than or equal to pivot.
If two pointers met ..
The main function that implements QuickSort arr -- > Array to be sorted , low -- > Starting index , high -- > Ending index.
pi is partitioning index , arr [ p ] is now at right place.
Separately sort elements before partition and after partition.
Function to pran array.
Driver code"
Solution in Python:
assistant
#Here is code to hoare 's vs Lomuto partition scheme in QuickSort and the other steps required.
 def partition ( arr , low , high ) :
	pivot = arr [ low ]
	i = low - 1
	j = high + 1
	while ( True ) :
		i += 1
		while ( arr [ i ] < pivot ) :
			i += 1
		j -= 1
		while ( arr [ j ] > pivot ) :
			j -= 1
		if ( i >= j ) :
			return j
		arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
def quickSort ( arr , low , high ) :
	if ( low < high ) :
		pi = partition ( arr , low , high )
		quickSort ( arr , low , pi )
		quickSort ( arr , pi + 1 , high )
def printArray ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
	print ( )
arr = [ 10 , 7 , 8 , 9 , 1 , 5 ]
n = len ( arr )
quickSort ( arr , 0 , n - 1 )
print ( " Sorted ▁ array : " )
printArray ( arr , n )