Question: Given an array A and an element xinA, write a linear time algorithm to implement the split function. That is , split the array A
Given an array A and an element xinA, write a linear time algorithm to implement the split function.
That is split the array A into all elements smaller than all elements equal to and all
elements larger than using only extra space.
Remark: When implementing, you shouldn't give as input to split. This would automatically copy
allocating memory and your code would be dead on arrival. Treat as a global array that your
function split can access.
Using the split operation, let us make another sorting algorithm.
Given an array choose a random element and split it using IN PLACE, LIKE THE PREVIOUS
ALROGITHM
Recursively sort and AGAIN, IN PLACE!
Tip: To do everything in place, instead of giving an array as an input to the function, give indices
For example: is an array and sort sorts all elements with indices between i and in This is how
you make a really fast sorting algorithm, that usually goes by the name QuickSort.
Please provide a detrailed explaination.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
